WordPress.org

Make WordPress Core

Ticket #45495: 45495.diff

File 45495.diff, 2.1 KB (added by pento, 18 months ago)
  • src/wp-includes/blocks.php

    diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php
    index 829d916bfd..8791f93642 100644
    a b function parse_blocks( $content ) { 
    262262 * @return string Updated post content.
    263263 */
    264264function do_blocks( $content ) {
    265         // If there are blocks in this content, we shouldn't run wpautop() on it later.
    266         $priority = has_filter( 'the_content', 'wpautop' );
    267         if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) {
    268                 remove_filter( 'the_content', 'wpautop', $priority );
    269                 add_filter( 'the_content', '_restore_wpautop_hook', $priority + 1 );
    270         }
    271 
    272265        $blocks = parse_blocks( $content );
    273266        $output = '';
    274267
    function do_blocks( $content ) { 
    276269                $output .= render_block( $block );
    277270        }
    278271
     272        // If there are blocks in this content, we shouldn't run wpautop() on it later.
     273        $priority = has_filter( 'the_content', 'wpautop' );
     274        if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) {
     275                remove_filter( 'the_content', 'wpautop', $priority );
     276                add_filter( 'the_content', '_restore_wpautop_hook', $priority + 1 );
     277        }
     278
    279279        return $output;
    280280}
    281281
  • tests/phpunit/tests/blocks/render.php

    diff --git a/tests/phpunit/tests/blocks/render.php b/tests/phpunit/tests/blocks/render.php
    index be41a4bb9a..05bfdeda3a 100644
    a b class WP_Test_Block_Render extends WP_UnitTestCase { 
    8787                return $content;
    8888        }
    8989
     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', '' );
     113                return $content;
     114        }
     115
    90116        public function test_can_nest_at_least_so_deep() {
    91117                $minimum_depth = 99;
    92118