Make WordPress Core

Changeset 45139


Ignore:
Timestamp:
04/08/2019 06:53:14 AM (6 years ago)
Author:
pento
Message:

Blocks: Allow for nested the_content calls within do_blocks().

When do_blocks() is run, it sets up some special handling of the wpautop filter, as we don't want wpautop to run on block content, but we do want it to be available for subsequent runs of the_content, which may be happening on non-block content.

As we set this up before rendering dynamic blocks, however, a dynamic block choosing to run the_content will cause unintentially structural deficiences in this particular recursive block tower.

Moving this handling to after dynamic blocks are rendered makes our tower lean a little less.

Props aldavigdis, pento.
Fixes #45495.

Location:
trunk
Files:
2 edited

Legend:

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

    r44576 r45139  
    263263 */
    264264function do_blocks( $content ) {
     265    $blocks = parse_blocks( $content );
     266    $output = '';
     267
     268    foreach ( $blocks as $block ) {
     269        $output .= render_block( $block );
     270    }
     271
    265272    // If there are blocks in this content, we shouldn't run wpautop() on it later.
    266273    $priority = has_filter( 'the_content', 'wpautop' );
     
    270277    }
    271278
    272     $blocks = parse_blocks( $content );
    273     $output = '';
    274 
    275     foreach ( $blocks as $block ) {
    276         $output .= render_block( $block );
    277     }
    278 
    279279    return $output;
    280280}
  • trunk/tests/phpunit/tests/blocks/render.php

    r44785 r45139  
    8585
    8686    function handle_shortcode( $atts, $content ) {
     87        return $content;
     88    }
     89
     90    /**
     91     * @ticket 45495
     92     */
     93    function test_nested_calls_to_the_content() {
     94        register_block_type(
     95            'core/test',
     96            array(
     97                'render_callback' => array(
     98                    $this,
     99                    'dynamic_the_content_call',
     100                ),
     101            )
     102        );
     103
     104        $content = "foo\n\nbar";
     105
     106        $the_content = apply_filters( 'the_content', '<!-- wp:core/test -->' . $content . '<!-- /wp:core/test -->' );
     107
     108        $this->assertSame( $content, $the_content );
     109    }
     110
     111    function dynamic_the_content_call( $attrs, $content ) {
     112        apply_filters( 'the_content', '' );
    87113        return $content;
    88114    }
Note: See TracChangeset for help on using the changeset viewer.