Skip to content
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

Improve image handling approach in Modern Image Formats #1259

Closed
adamsilverstein opened this issue May 30, 2024 · 3 comments · Fixed by #1772
Closed

Improve image handling approach in Modern Image Formats #1259

adamsilverstein opened this issue May 30, 2024 · 3 comments · Fixed by #1772
Labels
Needs Dev Anything that requires development (e.g. a pull request) no milestone PRs that do not have a defined milestone for release [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@adamsilverstein
Copy link
Member

Feature Description

Switch from using the_content filter to using wp_calculate_image_srcset when replacing images.

As @joemcgill points out in #1236 (review) we should probably switch the image processing approach. Currently the webp_uploads_update_image_references function is attached to the_content filter and processes all images on the page using a regex. Instead, we can leverage the filters core runs on images after it does a similar regex against the content. Namely, the wp_calculate_image_srcset or wp_content_img_tag filters are potential places to add our logic.

@adamsilverstein adamsilverstein added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) no milestone PRs that do not have a defined milestone for release labels May 30, 2024
@adamsilverstein adamsilverstein moved this to Not Started/Backlog 📆 in WP Performance 2024 May 30, 2024
@westonruter
Copy link
Member

westonruter commented May 30, 2024

And note that webp_uploads_wrap_image_in_picture() is necessarily using the wp_content_img_tag filter.

@mukeshpanchal27 mukeshpanchal27 added the Needs Dev Anything that requires development (e.g. a pull request) label Dec 18, 2024
@mukeshpanchal27 mukeshpanchal27 moved this from Not Started/Backlog 📆 to To Do 🔧 in WP Performance 2024 Dec 18, 2024
@joemcgill
Copy link
Member

Looking at this again today, I'd prefer using the wp_filter_content_tags filter as it would be the most straightforward change.

@b1ink0
Copy link
Contributor

b1ink0 commented Dec 31, 2024

@joemcgill
I believe the wp_filter_content_tags filter does not actually exist in the core, but there is a function named wp_filter_content_tags() which processes images and iframes. As described in the doc comment for wp_filter_content_tags() function, it is intended to convert old HTML markup to new HTML5 markup ref.

Instead, I believe the wp_content_img_tag filter would be a better option. This filter is defined inside the wp_filter_content_tags() function, which already performs regex to find the img tags. Using this filter would eliminate the need for additional regex that we are doing in the webp_uploads_update_image_references function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Dev Anything that requires development (e.g. a pull request) no milestone PRs that do not have a defined milestone for release [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Enhancement A suggestion for improvement of an existing feature
Projects
Status: Done 😃
Development

Successfully merging a pull request may close this issue.

5 participants