Make WordPress Core


Ignore:
Timestamp:
09/12/2023 07:18:34 PM (3 years ago)
Author:
flixos90
Message:

Posts, Post Types: Avoid unnecessarily parsing blocks twice in wp_trim_excerpt().

All blocks relevant for the excerpt are already being parsed in excerpt_remove_blocks(). Therefore running do_blocks() on the post content only to create the excerpt is unnecessary and wasteful from a performance perspective.

Props thekt12, spacedmonkey, mukesh27, joemcgill.
Fixes #58682.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r56559 r56560  
    39813981         * is wasteful and can lead to bugs in the image counting logic.
    39823982         */
    3983         $filter_removed = remove_filter( 'the_content', 'wp_filter_content_tags' );
     3983        $filter_image_removed = remove_filter( 'the_content', 'wp_filter_content_tags' );
     3984
     3985        /*
     3986         * Temporarily unhook do_blocks() since excerpt_remove_blocks( $text )
     3987         * handels block rendering needed for excerpt.
     3988         */
     3989        $filter_block_removed = remove_filter( 'the_content', 'do_blocks', 9 );
    39843990
    39853991        /** This filter is documented in wp-includes/post-template.php */
     
    39873993        $text = str_replace( ']]>', ']]>', $text );
    39883994
    3989         /**
     3995        // Restore the original filter if removed.
     3996        if ( $filter_block_removed ) {
     3997            add_filter( 'the_content', 'do_blocks', 9 );
     3998        }
     3999
     4000        /*
    39904001         * Only restore the filter callback if it was removed above. The logic
    39914002         * to unhook and restore only applies on the default priority of 10,
    39924003         * which is generally used for the filter callback in WordPress core.
    39934004         */
    3994         if ( $filter_removed ) {
     4005        if ( $filter_image_removed ) {
    39954006            add_filter( 'the_content', 'wp_filter_content_tags' );
    39964007        }
Note: See TracChangeset for help on using the changeset viewer.