Make WordPress Core


Ignore:
Timestamp:
09/26/2023 12:11:06 AM (19 months ago)
Author:
flixos90
Message:

Media: Ensure images within shortcodes are correctly considered for loading optimization attributes.

Prior to this change, images added in shortcodes would be considered separately from all other images within post content, which led to incorrect application of the loading optimization attributes loading="lazy" and fetchpriority="high".

This changeset changes the filter priority of wp_filter_content_tags() from the default 10 to 12 on the various content filters it is hooked in, in order to run that function after parsing shortcodes. While this may technically be considered a backward compatibility break, substantial research and lack of any relevant usage led to the assessment that the change is acceptable given its benefits.

An additional related fix included is that now the duplicate processing of images is prevented not only for post content blobs (the_content filter), but also for widget content blobs (widget_text_content and widget_block_content filters).

Props joemcgill, mukesh27, costdev, spacedmonkey, flixos90.
Fixes #58853.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/wpTrimExcerpt.php

    r56598 r56693  
    130130        wp_trim_excerpt( '', $post );
    131131
    132         $this->assertSame( 10, has_filter( 'the_content', 'wp_filter_content_tags' ), 'wp_filter_content_tags() was not restored in wp_trim_excerpt()' );
     132        $this->assertSame( 12, has_filter( 'the_content', 'wp_filter_content_tags' ), 'wp_filter_content_tags() was not restored in wp_trim_excerpt()' );
    133133    }
    134134
     
    142142
    143143        // Remove wp_filter_content_tags() from 'the_content' filter generally.
    144         remove_filter( 'the_content', 'wp_filter_content_tags' );
     144        remove_filter( 'the_content', 'wp_filter_content_tags', 12 );
    145145
    146146        wp_trim_excerpt( '', $post );
Note: See TracChangeset for help on using the changeset viewer.