[wp-trac] [WordPress Trac] #51865: Add filter to `wp_image_src_get_dimensions`
WordPress Trac
noreply at wordpress.org
Tue Nov 24 15:48:09 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: General | Version:
Severity: normal | Keywords: needs-patch
Focuses: |
-------------------------+-------------------------
`wp_image_src_get_dimensions()` was added in WordPress 5.5 as a way to
calculate the `height` and `width` attributes of a content image so that
WordPress could better support native lazy loading and improve calculation
of the responsive `sizes` attribute since the block editor often doesn't
add these attributes to the image markup saved in the editor.
This function works by comparing the image file from the `src` attribute
against all of the image sizes available for that attachment, in order to
find the dimensions. However, if a plugin has modified either the `src`
file or the attachment meta, this might return a `false`, resulting in the
full size dimensions to be used when calculating `height`, `width` and
`sizes` attributes.
Adding a filter to `wp_image_src_get_dimensions()` would allow developers
to fix these dimensions when they occur.
Additionally, the check for `wp_image_file_matches_image_meta()` in
`wp_image_src_get_dimensions()` can most likely be dropped, since it's
purpose is largely duplicative of the matching of files to attachment meta
that is done afterwards.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51865>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list