diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 829d916bfd..8791f93642 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -262,13 +262,6 @@ function parse_blocks( $content ) { * @return string Updated post content. */ function do_blocks( $content ) { - // If there are blocks in this content, we shouldn't run wpautop() on it later. - $priority = has_filter( 'the_content', 'wpautop' ); - if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) { - remove_filter( 'the_content', 'wpautop', $priority ); - add_filter( 'the_content', '_restore_wpautop_hook', $priority + 1 ); - } - $blocks = parse_blocks( $content ); $output = ''; @@ -276,6 +269,13 @@ function do_blocks( $content ) { $output .= render_block( $block ); } + // If there are blocks in this content, we shouldn't run wpautop() on it later. + $priority = has_filter( 'the_content', 'wpautop' ); + if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) { + remove_filter( 'the_content', 'wpautop', $priority ); + add_filter( 'the_content', '_restore_wpautop_hook', $priority + 1 ); + } + return $output; } diff --git a/tests/phpunit/tests/blocks/render.php b/tests/phpunit/tests/blocks/render.php index e7dc724740..f6b6513298 100644 --- a/tests/phpunit/tests/blocks/render.php +++ b/tests/phpunit/tests/blocks/render.php @@ -87,6 +87,32 @@ class WP_Test_Block_Render extends WP_UnitTestCase { return $content; } + /** + * @ticket 45495 + */ + function test_nested_calls_to_the_content() { + register_block_type( + 'core/test', + array( + 'render_callback' => array( + $this, + 'dynamic_the_content_call', + ), + ) + ); + + $content = "foo\n\nbar"; + + $the_content = apply_filters( 'the_content', '' . $content . '' ); + + $this->assertSame( $content, $the_content ); + } + + function dynamic_the_content_call( $attrs, $content ) { + apply_filters( 'the_content', '' ); + return $content; + } + public function test_can_nest_at_least_so_deep() { $minimum_depth = 99;