[wp-trac] [WordPress Trac] #51865: Add filter to `wp_image_src_get_dimensions`
WordPress Trac
noreply at wordpress.org
Thu Nov 26 16:04:15 UTC 2020
#51865: Add filter to `wp_image_src_get_dimensions`
-------------------------------------------------+-------------------------
Reporter: joemcgill | Owner: joemcgill
Type: enhancement | Status: assigned
Priority: normal | Milestone: 5.7
Component: Media | Version:
Severity: normal | Resolution:
Keywords: has-patch 2nd-opinion needs-unit- | Focuses:
tests |
-------------------------------------------------+-------------------------
Comment (by ianmjones):
This is a great change.
We found that since WP5.5 srcset was not being added for images offloaded
by WP Offload Media if they included "Object Versioning". That's a small
segment of numerics added just before the filename to help with CDN cache
busting in various scenarios.
`2020/11/puppies.jpg` becomes `2020/11/12131415/puppies.jpg`.
We were able to filter `wp_image_file_matches_image_meta` so that passed,
and that means intermediate sizes in the `src` now get a proper `srcset`
attribute on the `img` tag.
However, in `wp_image_src_get_dimensions` there's a check that the full
size image's "file" entry in the metadata is found in the image src, that
still fails and we can't work around it.
The proposed change here would help us also fix the problem for the full
size images as we'd be able to check our metadata for a match and supply
the size info.
However, I wonder if it would be possible to tweak the function a fraction
and so that ...
`if ( strpos( $image_src, $image_meta['file'] ) !== false ) {`
... becomes ...
`if ( strpos( $image_src, wp_basename( $image_meta['file'] ) ) !== false )
{`
That would improve the chances of matching greatly, and reduce the need
for plugins like WP Offload Media to have to do the work of finding a
match.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51865#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list