Make WordPress Core


Ignore:
Timestamp:
09/26/2023 12:11:06 AM (3 years 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/src/wp-includes/default-filters.php

    r56682 r56693  
    196196add_filter( 'the_content', 'shortcode_unautop' );
    197197add_filter( 'the_content', 'prepend_attachment' );
    198 add_filter( 'the_content', 'wp_filter_content_tags' );
    199198add_filter( 'the_content', 'wp_replace_insecure_home_url' );
     199add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop().
     200add_filter( 'the_content', 'wp_filter_content_tags', 12 ); // Runs after do_shortcode().
    200201
    201202add_filter( 'the_excerpt', 'wptexturize' );
     
    204205add_filter( 'the_excerpt', 'wpautop' );
    205206add_filter( 'the_excerpt', 'shortcode_unautop' );
    206 add_filter( 'the_excerpt', 'wp_filter_content_tags' );
    207207add_filter( 'the_excerpt', 'wp_replace_insecure_home_url' );
     208add_filter( 'the_excerpt', 'wp_filter_content_tags', 12 );
    208209add_filter( 'get_the_excerpt', 'wp_trim_excerpt', 10, 2 );
    209210
     
    231232add_filter( 'widget_text_content', 'wpautop' );
    232233add_filter( 'widget_text_content', 'shortcode_unautop' );
    233 add_filter( 'widget_text_content', 'wp_filter_content_tags' );
    234234add_filter( 'widget_text_content', 'wp_replace_insecure_home_url' );
    235235add_filter( 'widget_text_content', 'do_shortcode', 11 ); // Runs after wpautop(); note that $post global will be null when shortcodes run.
     236add_filter( 'widget_text_content', 'wp_filter_content_tags', 12 ); // Runs after do_shortcode().
    236237
    237238add_filter( 'widget_block_content', 'do_blocks', 9 );
    238 add_filter( 'widget_block_content', 'wp_filter_content_tags' );
    239239add_filter( 'widget_block_content', 'do_shortcode', 11 );
     240add_filter( 'widget_block_content', 'wp_filter_content_tags', 12 ); // Runs after do_shortcode().
    240241
    241242add_filter( 'block_type_metadata', 'wp_migrate_old_typography_shape' );
     
    626627add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
    627628
    628 // Shortcodes.
    629 add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop().
    630 
    631629// Media.
    632630add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' );
Note: See TracChangeset for help on using the changeset viewer.