WordPress / WordPress/performance
Consider supplying modern image format in response to `wp_get_attachment_image()`
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 461
- Forks
- 165
- Avg merge
- 11h 12m
- Merged PRs (30d)
- 28
Description
We should consider filtering the response to wp_get_attachment_image() to handle additional cases where a theme may be printing an image in ways other than the_content() and the_post_thumbnail().
Originally posted by @b1ink0 in #2178:
I was able to replicate this bug. It seems the issue is with the
webp_uploads_update_featured_image()function hooked topost_thumbnail_html, which only callswebp_uploads_img_tag_update_mime_type()and does not conditionally callwebp_uploads_wrap_image_in_picture()based onwebp_uploads_is_picture_element_enabled().And, right now we are using the
post_thumbnail_htmlfilter for the featured image, but we could use thewp_get_attachment_imagefilter as the bug reporter suggested. However, this filter would also include any image echoed using thewp_get_attachment_image()function, which is used for featured images and is also typically used by other plugins. So, I'm not sure whether the Modern Image Formats plugin should also handle those images.
The following was fixed by https://github.com/WordPress/performance/pull/2179:
Also, while trying to replicate this bug, I noticed that (Using Twenty Twenty-One) Image Widgets or widget blocks containing the Image block and Gallery block don’t get their sources replaced with modern image formats because the
webp_uploads_wrap_image_in_picture()function only allows thethe_contentcontext, while widgets send thewidget_block_contentcontext.
See also https://github.com/WordPress/performance/pull/2179#discussion_r2376479942 from @adamsilverstein:
lets avoid altering other plugin output for now, the unexpected change could break things or cause conflicts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with webp-uploads/hooks.php, especially webp_uploads_update_featured_image() and webp_uploads_img_tag_update_mime_type(), then compare them with webp_uploads_wrap_image_in_picture() in picture-element.php and webp_uploads_is_picture_element_enabled() in helper.php. Clarify whether wp_get_attachment_image() output should be changed without altering other plugin output, and define the expected behavior before implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100