Repository navigation
Require WP 6.3 and use core HTML and loading APIs - #1400
Draft
utkarshcloudinary wants to merge 6 commits into
Draft
utkarshcloudinary wants to merge 6 commits into
utkarshcloudinary wants to merge 6 commits into
Conversation
readme.txt already declares WordPress 6.3 as the minimum. Add the same "Requires at least" and "Requires PHP" headers to the plugin file, so WordPress blocks activation on older sites. Remove the code paths that only ran on WordPress versions below 6.3: the function_exists() checks for wp_get_original_image_path/url, has_block and wp_print_inline_script_tag, the get_post_parent() fallback, the pre-5.9 class-http.php include and the pre-5.1 render_block fallback for video blocks. The fallback callback stays, marked deprecated, for third-party callers. Use wp_admin_notice() (WP 6.4+) for the PHP version notice when it is available.
Replace shortcode_parse_atts() and str_replace() tag handling with WP_HTML_Tag_Processor (WP 6.2+). - Utils::parse_html_tag() reads the tag name and attributes with the HTML API. Values are decoded and not unslashed, and a ">" inside a value no longer cuts the tag short. Delivery::parse_element() and Utils::get_tag_attributes() use it. - Filter::add_front_end_attributes() sets the missing class with set_attribute(), instead of inserting text before "/>", which did nothing on tags without a self-closing slash. - The content filter no longer stores loading="lazy" in post content. The check called wp_lazy_loading_enabled with the wrong arguments, and a stored value stops core from finding above the fold images. - Remove the old srcset before wp_image_add_srcset_and_sizes(), which appends a second srcset instead of replacing the first one.
Cloudinary lazy load replaced every image with a placeholder, including the LCP image, which delays the largest paint. Follow the WordPress 6.3 loading optimization decisions instead: - An image with fetchpriority="high" is the LCP candidate and is never lazy loaded, so core's fetchpriority now takes effect. - An image with loading="lazy" or fetchpriority="low" is below the fold and is lazy loaded. - Other images count towards wp_omit_loading_attr_threshold (3 by default) in document order. The first ones load eagerly. The new cloudinary_lazy_load_in_initial_viewport filter can change the result per image. Delivery rebuilds the tag after core adds sizes="auto" (WP 6.7+), so run wp_img_tag_add_auto_sizes() on the rebuilt tag to keep it. The breakpoints e2e fixture now marks its image loading="lazy", as it is the only image in the post and would otherwise load eagerly.
The HTML API parser keeps backslashes in attribute values, which shortcode_parse_atts() used to strip. update_post_meta() unslashes the value, so the cached replacement for alt="C:\new" was saved as alt="C:new" and a cached page rendered a different tag than an uncached one. Slash the replacements before they are saved, and move the write into Delivery::update_context_cache() so it can be tested.
The breakpoints fixture image is now natively lazy loaded, and Delivery keeps the "auto" that WordPress 6.7+ adds to the sizes of lazy loaded images. Update the expected sizes attribute.
- Video blocks: replace the src and poster through the HTML API in the new Video::replace_tag_urls(). get_tag_attributes() now returns decoded values, so str_replace() missed URLs with "&" in the HTML and left the local URL when the Cloudinary player is off. - Stop loading the plugin on WordPress below 6.3 and show a notice. The header only blocks activation from the admin, not updates with Composer or a zip file. - Clear the replacement cache on cloudinary_version_upgrade. Cached tags skip rebuild_tag(), so pages kept the old markup. - Check the lazy load bypass classes before the viewport check, so bypassed images do not use up the eager places. - Call _deprecated_function() in the deprecated video callback. - Move remove_tag_attribute() to Utils. - Tests: skip the sizes="auto" test before WP 6.7, compare attributes instead of exact markup, parse tags through get_media_tags(), cover the new code, and add an e2e case for the first image.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sets WordPress 6.3 as the minimum version (
readme.txtalready says 6.3) and uses the core APIs that this makes available.Lazy load no longer replaces images at the top of the page. It uses the same signals as core (6.3):
Cleanup: removes the fallbacks for WP versions below 6.3 (
function_exists()guards, theget_post_parent()fallback, theclass-http.phpinclude, the pre-5.1render_blockvideo fallback).filter_video_block_render_block()stays, marked@deprecated, for third-party callers. The PHP version notice useswp_admin_notice()when it is available.Not included: the Interactivity API (needs 6.5 and a gallery/player rewrite) and
wp_admin_notice()for the plugin's own notice UI (that UI has icons and timed dismiss, which core does not support).Approach
>inside a value no longer cuts the tag short.Lazy_Load::bypass_lazy_load(), andsizes="auto"on rebuilt tags.update_post_meta(). Because the parser now keeps backslashes, a cached page renderedalt="C:\new"asalt="C:new"while the uncached page did not. A regression test covers it (fails without the fix).Evidence
The same parser code, run against the WP 6.3
WP_HTML_Tag_Processor:Class insertion on a tag without a self-closing slash:
<img src="a.jpg">stays unchanged (there is no/>to replace)<img class="wp-image-12" src="a.jpg">sizeson a rebuilt lazy image (WP 7.2 RC4):sizes="(max-width: 300px) 100vw, 300px"(core'sautowas dropped when the tag was rebuilt)sizes="auto, (max-width: 300px) 100vw, 300px"New unit tests are in
tests/phpunit/tests/test-wp-core-apis.phpandtest-delivery-parse-element.php. They cover the parser, the class insertion, the srcset removal, the viewport threshold and core hints, and the new filter.Browser check (Chrome DevTools, local wp-env, WP 7.2 RC4, lazy load on, 6 synced images, image 5 has
fetchpriority="high"):developfetchpriority="high")loading="lazy")fetchpriority="high")wp_omit_loading_attr_threshold= 1: only the hero is eager.cloudinary_lazy_load_in_initial_viewport= false: all lazy, same asdevelop.developdrops core'ssizes="auto"from lazy images; this branch keeps it. Each image has onesrcset.QA notes
loadingattributes. On the front end, the first 3 images (default threshold) have a Cloudinarysrcand nodata-cloudinary="lazy". The later images have the placeholder and lazy load on scroll.add_filter( 'wp_omit_loading_attr_threshold', fn() => 1 );. Only the first image loads eagerly.fetchpriority="high"and is never a lazy placeholder.add_filter( 'cloudinary_lazy_load_in_initial_viewport', '__return_false' );. All images are lazy loaded again, as ondevelop.sizes="auto, …"on WP 6.7 or higher, and each image has only onesrcset.Merge Danger
Door: two-way. No data or option changes. A revert restores the old behaviour. Content saved after this change no longer contains
loading="lazy", which is the core default.Blast Radius: front end markup of every image that Delivery rewrites.
wp_omit_loading_attr_thresholdorcloudinary_lazy_load_in_initial_viewport.cloudinary_parse_element/cloudinary_pre_image_tagfilters that expected the old output can see different values.