Skip to content

Consider supplying modern image format in response to wp_get_attachment_image() #2299

@westonruter

Description

@westonruter

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 to post_thumbnail_html, which only calls webp_uploads_img_tag_update_mime_type() and does not conditionally call webp_uploads_wrap_image_in_picture() based on webp_uploads_is_picture_element_enabled().

And, right now we are using the post_thumbnail_html filter for the featured image, but we could use the wp_get_attachment_image filter as the bug reporter suggested. However, this filter would also include any image echoed using the wp_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.

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 the the_content context, while widgets send the widget_block_content context.

See also #2179 (comment) from @adamsilverstein:

lets avoid altering other plugin output for now, the unexpected change could break things or cause conflicts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Modern Image FormatsIssues for the Modern Image Formats plugin (formerly WebP Uploads)[Type] EnhancementA suggestion for improvement of an existing feature

    Type

    No type

    Projects

    Status

    Not Started/Backlog 📆

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions