From c74cdb2782938d23f0685ae12dfce8561a9146bd Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 17:08:53 +0100 Subject: [PATCH 01/19] Extract get_hooked_block_markup function --- src/wp-includes/blocks.php | 12 ++++++--- .../phpunit/tests/blocks/getHookedBlockMarkup | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/tests/blocks/getHookedBlockMarkup diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 591a7971cafb0..763e506727fed 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -757,6 +757,10 @@ function get_hooked_blocks() { return $hooked_blocks; } +function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) { + return get_comment_delimited_block_content( $hooked_block_type, array(), '' ); +} + /** * Returns a function that injects the theme attribute into, and hooked blocks before, a given block. * @@ -813,7 +817,7 @@ function make_before_block_visitor( $hooked_blocks, $context ) { */ $hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); foreach ( $hooked_block_types as $hooked_block_type ) { - $markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' ); + $markup .= get_hooked_block_markup( $parent_block, $hooked_block_type ); } } @@ -826,7 +830,7 @@ function make_before_block_visitor( $hooked_blocks, $context ) { /** This filter is documented in wp-includes/blocks.php */ $hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); foreach ( $hooked_block_types as $hooked_block_type ) { - $markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' ); + $markup .= get_hooked_block_markup( $block, $hooked_block_type ); } return $markup; @@ -874,7 +878,7 @@ function make_after_block_visitor( $hooked_blocks, $context ) { /** This filter is documented in wp-includes/blocks.php */ $hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); foreach ( $hooked_block_types as $hooked_block_type ) { - $markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' ); + $markup .= get_hooked_block_markup( $block, $hooked_block_type ); } if ( $parent_block && ! $next ) { @@ -888,7 +892,7 @@ function make_after_block_visitor( $hooked_blocks, $context ) { /** This filter is documented in wp-includes/blocks.php */ $hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); foreach ( $hooked_block_types as $hooked_block_type ) { - $markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' ); + $markup .= get_hooked_block_markup( $parent_block, $hooked_block_type ); } } diff --git a/tests/phpunit/tests/blocks/getHookedBlockMarkup b/tests/phpunit/tests/blocks/getHookedBlockMarkup new file mode 100644 index 0000000000000..1b7d85aff021b --- /dev/null +++ b/tests/phpunit/tests/blocks/getHookedBlockMarkup @@ -0,0 +1,26 @@ + 'tests/anchor-block', + ); + + $actual = get_hooked_block_markup( $anchor_block, 'tests/hooked-block' ); + $this->assertSame( '', $actual ); + } +} From 552c66e63a7b6a5f3b2232dca0b76671fa157857 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 17:31:48 +0100 Subject: [PATCH 02/19] Set ignoredHookedBlocks metadata --- src/wp-includes/blocks.php | 14 ++++++++++++++ tests/phpunit/tests/blocks/getHookedBlockMarkup | 1 + 2 files changed, 15 insertions(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 763e506727fed..c548c139c4d62 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -758,6 +758,20 @@ function get_hooked_blocks() { } function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) { + if ( + isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) && + in_array( $hooked_block_type, $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) + ) { + return ''; + } + + // The following is only needed for the REST API endpoint. + // However, its presence does not affect the frontend. + if ( ! isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { + $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array(); + } + $anchor_block['attrs']['metadata']['ignoredHookedBlocks'][] = $hooked_block_type; + return get_comment_delimited_block_content( $hooked_block_type, array(), '' ); } diff --git a/tests/phpunit/tests/blocks/getHookedBlockMarkup b/tests/phpunit/tests/blocks/getHookedBlockMarkup index 1b7d85aff021b..5ecd27df25bf9 100644 --- a/tests/phpunit/tests/blocks/getHookedBlockMarkup +++ b/tests/phpunit/tests/blocks/getHookedBlockMarkup @@ -21,6 +21,7 @@ class Tests_Blocks_GetHookedBlockMarkup extends WP_UnitTestCase ); $actual = get_hooked_block_markup( $anchor_block, 'tests/hooked-block' ); + $this->assertSame( array( 'tests/hooked-block' ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ); $this->assertSame( '', $actual ); } } From 498dcf274db8e94cefbecbb5109b74e0bef130cb Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 17:34:26 +0100 Subject: [PATCH 03/19] Rewrite a bit --- src/wp-includes/blocks.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index c548c139c4d62..e0766b69832a1 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -758,18 +758,16 @@ function get_hooked_blocks() { } function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) { - if ( - isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) && - in_array( $hooked_block_type, $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) - ) { - return ''; + if ( isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { + if ( in_array( $hooked_block_type, $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { + return ''; + } + } else { + $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array(); } // The following is only needed for the REST API endpoint. // However, its presence does not affect the frontend. - if ( ! isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { - $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array(); - } $anchor_block['attrs']['metadata']['ignoredHookedBlocks'][] = $hooked_block_type; return get_comment_delimited_block_content( $hooked_block_type, array(), '' ); From 450c05f0efdc8aa0dce54813e7ea037aac459329 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 17:36:32 +0100 Subject: [PATCH 04/19] Rewrite a bit more --- src/wp-includes/blocks.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index e0766b69832a1..71e931d8da80b 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -758,14 +758,14 @@ function get_hooked_blocks() { } function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) { - if ( isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { - if ( in_array( $hooked_block_type, $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { - return ''; - } - } else { + if ( ! isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array(); } + if ( in_array( $hooked_block_type, $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { + return ''; + } + // The following is only needed for the REST API endpoint. // However, its presence does not affect the frontend. $anchor_block['attrs']['metadata']['ignoredHookedBlocks'][] = $hooked_block_type; From bef23016d87e37f5c0d608326ae5045eb27c2c36 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 17:40:00 +0100 Subject: [PATCH 05/19] Add ticket PHPDoc --- .../phpunit/tests/blocks/getHookedBlockMarkup | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/phpunit/tests/blocks/getHookedBlockMarkup b/tests/phpunit/tests/blocks/getHookedBlockMarkup index 5ecd27df25bf9..942bd6893f385 100644 --- a/tests/phpunit/tests/blocks/getHookedBlockMarkup +++ b/tests/phpunit/tests/blocks/getHookedBlockMarkup @@ -13,6 +13,8 @@ class Tests_Blocks_GetHookedBlockMarkup extends WP_UnitTestCase { /** + * @ticket 59646 + * * @covers ::get_hooked_block_markup */ public function test_get_hooked_block_markup() { @@ -24,4 +26,24 @@ class Tests_Blocks_GetHookedBlockMarkup extends WP_UnitTestCase $this->assertSame( array( 'tests/hooked-block' ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ); $this->assertSame( '', $actual ); } + + /** + * @ticket 59646 + * + * @covers ::get_hooked_block_markup + */ + public function test_get_hooked_block_markup_if_block_is_already_hooked() { + $anchor_block = array( + 'blockName' => 'tests/anchor-block', + 'attrs' => array( + 'metadata' => array( + 'ignoredHookedBlocks' => array( 'tests/hooked-block' ), + ), + ) + ); + + $actual = get_hooked_block_markup( $anchor_block, 'tests/hooked-block' ); + $this->assertSame( array( 'tests/hooked-block' ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ); + $this->assertSame( '', $actual ); + } } From 061cbd6d6887db516d7b5198986bf57f3c57213b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 17:46:23 +0100 Subject: [PATCH 06/19] Inject hooked blocks into modified templates and parts --- src/wp-includes/block-template-utils.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index 265758b922840..d7089b65787c7 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -894,6 +894,14 @@ function _build_block_template_result_from_post( $post ) { } } + $hooked_blocks = get_hooked_blocks(); + if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { + $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template ); + $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template ); + $blocks = parse_blocks( $template->content ); + $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); + } + return $template; } From acbd7f2cc5a173f0e44615afc7be6c9fbe40de15 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 11:20:42 +0100 Subject: [PATCH 07/19] Relax test assertion a bit --- tests/phpunit/tests/blocks/getHookedBlocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/getHookedBlocks.php b/tests/phpunit/tests/blocks/getHookedBlocks.php index 4052e2a36fe36..1f897b3a0fa39 100644 --- a/tests/phpunit/tests/blocks/getHookedBlocks.php +++ b/tests/phpunit/tests/blocks/getHookedBlocks.php @@ -176,7 +176,7 @@ public function test_loading_template_part_with_hooked_blocks() { $this->assertStringContainsString( '' - . '', + . '' + '' . '', $template->content ); @@ -215,7 +215,7 @@ public function test_loading_pattern_with_hooked_blocks() { $pattern['content'] ); $this->assertStringContainsString( - '' + '' . '
' . '', str_replace( array( "\n", "\t" ), '', $pattern['content'] ) From ca6b4742f2583c7810a958a067a07afdad1a97dd Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 15:16:57 +0100 Subject: [PATCH 09/19] Fix test --- tests/phpunit/tests/blocks/getHookedBlocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/getHookedBlocks.php b/tests/phpunit/tests/blocks/getHookedBlocks.php index ca44f11ca2dab..66a9e00efea69 100644 --- a/tests/phpunit/tests/blocks/getHookedBlocks.php +++ b/tests/phpunit/tests/blocks/getHookedBlocks.php @@ -176,7 +176,7 @@ public function test_loading_template_part_with_hooked_blocks() { $this->assertStringContainsString( '' - . '', $template->content ); $this->assertStringNotContainsString( From 3ad8dce0f9c0553721600b149e7ee02bcb0eefe0 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 15:54:26 +0100 Subject: [PATCH 10/19] Relax tests --- .../tests/blocks/wpBlockPatternsRegistry.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php b/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php index 01050a2c5f2ad..24dc0bfc7d5b0 100644 --- a/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php +++ b/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php @@ -381,14 +381,10 @@ public function test_get_all_registered_includes_hooked_blocks() { $pattern_three['name'] = 'test/three'; $pattern_three['content'] .= ''; - $expected = array( - $pattern_one, - $pattern_two, - $pattern_three, - ); - $registered = $this->registry->get_all_registered(); - $this->assertSame( $expected, $registered ); + $this->assertCount( 3, $registered ); + $this->assertStringEndsWith( '', $registered[1]['content'] ); + $this->assertStringEndsWith( '', $registered[2]['content'] ); } /** @@ -444,11 +440,8 @@ public function test_get_registered_includes_hooked_blocks() { ); $this->registry->register( 'test/two', $pattern_two ); - $pattern_one['name'] = 'test/one'; - $pattern_one['content'] = '' . $pattern_one['content']; - $pattern = $this->registry->get_registered( 'test/one' ); - $this->assertSame( $pattern_one, $pattern ); + $this->assertStringStartsWith( '', $pattern['content'] ); } /** From df1fc75f077718379eabf92899c8ab6acadecb7b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 16:05:16 +0100 Subject: [PATCH 11/19] Add some assertions for ignoredHookedBlocks --- tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php b/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php index 24dc0bfc7d5b0..1cc0f472bcdab 100644 --- a/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php +++ b/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php @@ -384,7 +384,9 @@ public function test_get_all_registered_includes_hooked_blocks() { $registered = $this->registry->get_all_registered(); $this->assertCount( 3, $registered ); $this->assertStringEndsWith( '', $registered[1]['content'] ); + $this->assertStringContainsString( '"metadata":{"ignoredHookedBlocks":["tests/my-block"]}', $registered[1]['content'] ); $this->assertStringEndsWith( '', $registered[2]['content'] ); + $this->assertStringContainsString( '"metadata":{"ignoredHookedBlocks":["tests/my-block"]}', $registered[2]['content'] ); } /** @@ -442,6 +444,7 @@ public function test_get_registered_includes_hooked_blocks() { $pattern = $this->registry->get_registered( 'test/one' ); $this->assertStringStartsWith( '', $pattern['content'] ); + $this->assertStringContainsString( '"metadata":{"ignoredHookedBlocks":["tests/my-block"]}', $pattern['content'] ); } /** From 9339ea2308e2804fc053c62118634e849260591f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 21:08:46 +0100 Subject: [PATCH 12/19] Rename test --- tests/phpunit/tests/blocks/getHookedBlockMarkup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/getHookedBlockMarkup b/tests/phpunit/tests/blocks/getHookedBlockMarkup index 942bd6893f385..4c1b0014882b2 100644 --- a/tests/phpunit/tests/blocks/getHookedBlockMarkup +++ b/tests/phpunit/tests/blocks/getHookedBlockMarkup @@ -17,7 +17,7 @@ class Tests_Blocks_GetHookedBlockMarkup extends WP_UnitTestCase * * @covers ::get_hooked_block_markup */ - public function test_get_hooked_block_markup() { + public function test_get_hooked_block_markup_adds_metadata() { $anchor_block = array( 'blockName' => 'tests/anchor-block', ); From 5289f74355190c7740ff82757b4dcb34e92ef40a Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 21:17:19 +0100 Subject: [PATCH 13/19] Add PHPDoc --- src/wp-includes/blocks.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 71e931d8da80b..c6b08afe9a5b9 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -757,6 +757,19 @@ function get_hooked_blocks() { return $hooked_blocks; } +/** + * Conditionally returns the markup for a given hooked block type. + * + * Accepts two arguments: A reference to an anchor block, and the name of a hooked block type. + * If the anchor block has already been processed, and the given hooked block type is in the list + * of ignored hooked blocks, an empty string is returned. + * + * @since 6.5.0 + * + * @param array $anchor_block The anchor block. Passed by reference. + * @param string $hooked_block_type The name of the hooked block type. + * @return string The markup for the given hooked block type, or an empty string if the block is ignored. + */ function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) { if ( ! isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) { $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array(); From 7dc3dfa4e1e528c210342e1f306ee1ee636f5823 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Nov 2023 21:20:23 +0100 Subject: [PATCH 14/19] Tabs vs spaces --- src/wp-includes/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index c6b08afe9a5b9..63e9bf4604e77 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -766,7 +766,7 @@ function get_hooked_blocks() { * * @since 6.5.0 * - * @param array $anchor_block The anchor block. Passed by reference. + * @param array $anchor_block The anchor block. Passed by reference. * @param string $hooked_block_type The name of the hooked block type. * @return string The markup for the given hooked block type, or an empty string if the block is ignored. */ From dc3565918fcfe32013dbbefc5630a2815a7b949b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 29 Nov 2023 13:35:54 +0100 Subject: [PATCH 15/19] Missing .php file extension :facepalm: --- .../blocks/{getHookedBlockMarkup => getHookedBlockMarkup.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/phpunit/tests/blocks/{getHookedBlockMarkup => getHookedBlockMarkup.php} (100%) diff --git a/tests/phpunit/tests/blocks/getHookedBlockMarkup b/tests/phpunit/tests/blocks/getHookedBlockMarkup.php similarity index 100% rename from tests/phpunit/tests/blocks/getHookedBlockMarkup rename to tests/phpunit/tests/blocks/getHookedBlockMarkup.php From ef73917eaa4507c49b0d7ebe860412da3d9c2d73 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 29 Nov 2023 13:49:07 +0100 Subject: [PATCH 16/19] Add test case --- .../tests/blocks/getHookedBlockMarkup.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/phpunit/tests/blocks/getHookedBlockMarkup.php b/tests/phpunit/tests/blocks/getHookedBlockMarkup.php index 4c1b0014882b2..2406c787b6b8e 100644 --- a/tests/phpunit/tests/blocks/getHookedBlockMarkup.php +++ b/tests/phpunit/tests/blocks/getHookedBlockMarkup.php @@ -46,4 +46,24 @@ public function test_get_hooked_block_markup_if_block_is_already_hooked() { $this->assertSame( array( 'tests/hooked-block' ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ); $this->assertSame( '', $actual ); } + + /** + * @ticket 59646 + * + * @covers ::get_hooked_block_markup + */ + public function test_get_hooked_block_markup_adds_to_ignored_hooked_blocks() { + $anchor_block = array( + 'blockName' => 'tests/anchor-block', + 'attrs' => array( + 'metadata' => array( + 'ignoredHookedBlocks' => array( 'tests/hooked-block' ), + ), + ) + ); + + $actual = get_hooked_block_markup( $anchor_block, 'tests/other-hooked-block' ); + $this->assertSame( array( 'tests/hooked-block', 'tests/other-hooked-block' ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ); + $this->assertSame( '', $actual ); + } } From 41c2f1c266da9aa5f7c2c2491d61cd894df83ead Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 30 Nov 2023 11:01:10 +0100 Subject: [PATCH 17/19] Coding Standards --- tests/phpunit/tests/blocks/getHookedBlockMarkup.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/blocks/getHookedBlockMarkup.php b/tests/phpunit/tests/blocks/getHookedBlockMarkup.php index 2406c787b6b8e..918ad97031e2e 100644 --- a/tests/phpunit/tests/blocks/getHookedBlockMarkup.php +++ b/tests/phpunit/tests/blocks/getHookedBlockMarkup.php @@ -10,8 +10,7 @@ * @group blocks * @group block-hooks */ -class Tests_Blocks_GetHookedBlockMarkup extends WP_UnitTestCase -{ +class Tests_Blocks_GetHookedBlockMarkup extends WP_UnitTestCase { /** * @ticket 59646 * @@ -39,7 +38,7 @@ public function test_get_hooked_block_markup_if_block_is_already_hooked() { 'metadata' => array( 'ignoredHookedBlocks' => array( 'tests/hooked-block' ), ), - ) + ), ); $actual = get_hooked_block_markup( $anchor_block, 'tests/hooked-block' ); @@ -59,7 +58,7 @@ public function test_get_hooked_block_markup_adds_to_ignored_hooked_blocks() { 'metadata' => array( 'ignoredHookedBlocks' => array( 'tests/hooked-block' ), ), - ) + ), ); $actual = get_hooked_block_markup( $anchor_block, 'tests/other-hooked-block' ); From f3dbb7a3d5c60b3c06cd20356be23150f9df4cb1 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Dec 2023 16:19:46 +0100 Subject: [PATCH 18/19] Revert "Inject hooked blocks into modified templates and parts" This reverts commit 061cbd6d6887db516d7b5198986bf57f3c57213b. --- src/wp-includes/block-template-utils.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index d7089b65787c7..265758b922840 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -894,14 +894,6 @@ function _build_block_template_result_from_post( $post ) { } } - $hooked_blocks = get_hooked_blocks(); - if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { - $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template ); - $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template ); - $blocks = parse_blocks( $template->content ); - $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); - } - return $template; } From f4379e1d2a8cb9812f00fc51e7d8c5ff12f253bf Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Dec 2023 16:23:01 +0100 Subject: [PATCH 19/19] Mark get_hooked_block_markup() as private --- src/wp-includes/blocks.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 63e9bf4604e77..431e2b015332c 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -764,7 +764,10 @@ function get_hooked_blocks() { * If the anchor block has already been processed, and the given hooked block type is in the list * of ignored hooked blocks, an empty string is returned. * + * This function is meant for internal use only. + * * @since 6.5.0 + * @access private * * @param array $anchor_block The anchor block. Passed by reference. * @param string $hooked_block_type The name of the hooked block type.