-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Responsive image attributes #1819
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1819 +/- ##
============================================
+ Coverage 94.74% 94.98% +0.24%
- Complexity 1534 1535 +1
============================================
Files 48 48
Lines 3632 3629 -3
============================================
+ Hits 3441 3447 +6
+ Misses 191 182 -9
Continue to review full report at Codecov.
|
lib/Image.php
Outdated
public function img_sizes( $size = "full" ) { | ||
$img_sizes = wp_get_attachment_image_sizes($this->ID, $size); | ||
$img_sizes = apply_filters('timber/image/img_sizes', $img_sizes, $this->ID); | ||
$img_sizes = apply_filters('timber_image_img_sizes', $img_sizes, $this->ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're deprecating this filter style, so you can remove
$img_sizes = apply_filters('timber_image_img_sizes', $img_sizes, $this->ID); |
Thank you @maxxwv! This looks like a good implementation of the WP methods. Before we merge, I want to make sure we have test coverage (even though it's a pretty simple thing, I want to make sure the functionality is always checked). Is that something you'd be up for trying? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like such a simple solution 🎉. Great stuff! And you also included examples, which is always great! Thanks for that!
I add some comments about the filters, because this is really my only concern right now.
lib/Image.php
Outdated
public function srcset( $size = "full" ) { | ||
$srcset = wp_get_attachment_image_srcset($this->ID, $size); | ||
$srcset = apply_filters('timber/image/srcset', $srcset, $this->ID); | ||
$srcset = apply_filters('timber_image_srcset', $srcset, $this->ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$srcset = apply_filters('timber_image_srcset', $srcset, $this->ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old filter style, see Jared’s review.
lib/Image.php
Outdated
*/ | ||
public function srcset( $size = "full" ) { | ||
$srcset = wp_get_attachment_image_srcset($this->ID, $size); | ||
$srcset = apply_filters('timber/image/srcset', $srcset, $this->ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure if we should add this filter, because the wp_get_attachment_image_srcset()
function already provides 3 filters to filter the resulting srcset. What would be the benefit of having this against using the filters in wp_get_attachment_image_srcset()
?
lib/Image.php
Outdated
*/ | ||
public function img_sizes( $size = "full" ) { | ||
$img_sizes = wp_get_attachment_image_sizes($this->ID, $size); | ||
$img_sizes = apply_filters('timber/image/img_sizes', $img_sizes, $this->ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here, I’m not sure if we need this filter at all, because wp_get_attachment_image_sizes()
calls wp_calculate_image_sizes()
in the last line, which in turn has a wp_calculate_image_sizes
filter in the last line. So the timber/image/img_sizes
filter would be called immediately after wp_calculate_image_sizes
. What would be the benefit of this?
Thanks for the comments! @jarednova - Sure, I'll take a stab at some basic tests, though honestly it's been a while since I've done unit testing so I can't guarantee much there. I'll look at the test-timber-image.php file and maybe the resize tests for examples and inspiration, unless there's a more appropriate place. @gchtr - I'm fine with pulling out those filters. I just put them in to match the src() interface more closely, to be honest. I'll pull them out in the next revision. I was also thinking it could be handy to have a method that runs both these methods and returns a single string of the attributes, as neither is really all that useful on their own. Thoughts or opinions? |
…sive_image * 'master' of https://github.com/timber/timber: Fix for older php versions Added simple current page item test Add comments and apply coding standards Added depth arg from TimberMenu Added filters for plugins to hook into TimberMenu
…nto responsive_image * 'responsive_image' of https://github.com/maxxwv/timber:
@gchtr @jarednova - not sure what to do about the coverage failure, but everything else should be good to go. Let me know if there's anything else you need from me. |
also some bonus `@codeCoverageIgnore`s on some deprecated functions to help juice code coverage scores
Everything's looking good @maxxwv. I changed the spacing to match WP style (tabs > spaces). The coverage failure was b/c of the Thanks again for the code, tests and examples for the docs! |
The phpdoc example provided uses |
Issue
I didn't see an easy way to get the srcset and sizes attributes for a Timber\Image object that was as simple as
post.thumbnail.src
.Solution
It seemed like a good idea to add
srcset
andsizes
as public methods, allowingpost.thumbnail.srcset
andpost.thumbnail.sizes
. Unfortunately,.sizes
didn't work butimg_sizes
did.Impact
As far as I can tell, none.
Usage Changes
Should be no impact.
Considerations
For whatever reason, creating a size() method in the Image object wasn't working. It didn't throw an error, just that
post.thumbnail.sizes
didn't ever call the method. It'd be a more intuitive call thanimg_sizes
, which would be nice.Testing
There's really nothing to fail, it's just a method to get the data that's more in keeping with the rest of the project.