From 34c64939bc30066b7639d49237e6a06849e9a7c7 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin <622599+aaronjorbin@users.noreply.github.com> Date: Tue, 15 Apr 2025 14:37:53 -0500 Subject: [PATCH 01/15] Apply patch from Obenland --- .../blocks/applyBlockHooksToContentFromPostObject.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php index df9d560ac9139..da6465868dc24 100644 --- a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php +++ b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php @@ -88,6 +88,15 @@ public static function wpSetUpBeforeClass() { ), ) ); + + register_block_type( + 'tests/other-hooked-block', + array( + 'block_hooks' => array( + 'core/post-content' => 'after', + ), + ) + ); } /** From 77111430379dd2880ee922609654f22a75a28ab2 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 15:52:24 +0200 Subject: [PATCH 02/15] Block Hooks: Suppress insertion of hooked blocks in before/after position into post object content --- src/wp-includes/blocks.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 31f1b224692a7..2b9cc84b6d48d 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1129,9 +1129,25 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i * We also need to cover the case where the hooked block is not present in * `$content` at first and we're allowed to insert it once -- but not again. */ - $suppress_single_instance_blocks = static function ( $hooked_block_types ) use ( &$block_allows_multiple_instances, $content ) { + $suppress_single_instance_blocks = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( &$block_allows_multiple_instances, $content, $context ) { static $single_instance_blocks_present_in_content = array(); foreach ( $hooked_block_types as $index => $hooked_block_type ) { + if ( $context instanceof WP_Post ) { + $wrapper_block_type = 'core/post-content'; + if ( 'wp_navigation' === $context->post_type ) { + $wrapper_block_type = 'core/navigation'; + } elseif ( 'wp_block' === $context->post_type ) { + $wrapper_block_type = 'core/block'; + } + + if ( + $wrapper_block_type === $anchor_block_type && + in_array( $relative_position, array( 'before', 'after' ), true ) + ) { + $hooked_block_types = array(); + } + } + if ( ! isset( $block_allows_multiple_instances[ $hooked_block_type ] ) ) { $hooked_block_type_definition = WP_Block_Type_Registry::get_instance()->get_registered( $hooked_block_type ); @@ -1157,7 +1173,7 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } return $hooked_block_types; }; - add_filter( 'hooked_block_types', $suppress_single_instance_blocks, PHP_INT_MAX ); + add_filter( 'hooked_block_types', $suppress_single_instance_blocks, PHP_INT_MAX, 3 ); $content = traverse_and_serialize_blocks( parse_blocks( $content ), $before_block_visitor, From 8012a6cb64bb12c2f4c038507355f096ea6a3b98 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 15:57:28 +0200 Subject: [PATCH 03/15] Unregister test block type during teardown --- .../tests/blocks/applyBlockHooksToContentFromPostObject.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php index da6465868dc24..03349aa5ca101 100644 --- a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php +++ b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php @@ -109,6 +109,7 @@ public static function wpTearDownAfterClass() { $registry->unregister( 'tests/hooked-block' ); $registry->unregister( 'tests/hooked-block-first-child' ); + $registry->unregister( 'tests/other-hooked-block' ); } /** From 999392c71c9dc27936dac43f9825ff85be8edbd3 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 15:58:30 +0200 Subject: [PATCH 04/15] Rename test block type --- .../tests/blocks/applyBlockHooksToContentFromPostObject.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php index 03349aa5ca101..e018d97080ee2 100644 --- a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php +++ b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php @@ -90,7 +90,7 @@ public static function wpSetUpBeforeClass() { ); register_block_type( - 'tests/other-hooked-block', + 'tests/hooked-block-after-post-content', array( 'block_hooks' => array( 'core/post-content' => 'after', @@ -109,7 +109,7 @@ public static function wpTearDownAfterClass() { $registry->unregister( 'tests/hooked-block' ); $registry->unregister( 'tests/hooked-block-first-child' ); - $registry->unregister( 'tests/other-hooked-block' ); + $registry->unregister( 'tests/hooked-block-after-post-content' ); } /** From 6e12f44b2555852d6e0eaae898ca989d622a4135 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 16:11:17 +0200 Subject: [PATCH 05/15] Add test coverage for filter-added hooked block before Post Content --- ...applyBlockHooksToContentFromPostObject.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php index e018d97080ee2..c27a3d6362976 100644 --- a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php +++ b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php @@ -140,6 +140,33 @@ public function test_apply_block_hooks_to_content_from_post_object_respects_igno $this->assertSame( $expected, $actual ); } + /** + * @ticket 63287 + */ + public function test_apply_block_hooks_to_content_from_post_object_does_not_insert_hooked_block_before_container_block() { + $filter = function ( $hooked_block_types, $relative_position, $anchor_block_type ) { + if ( 'core/post-content' === $anchor_block_type && 'before' === $relative_position ) { + $hooked_block_types[] = 'tests/dynamically-hooked-block-before-post-content'; + } + + return $hooked_block_types; + }; + + $expected = '' . + self::$post->post_content . + ''; + + add_filter( 'hooked_block_types', $filter, 10, 3 ); + $actual = apply_block_hooks_to_content_from_post_object( + self::$post->post_content, + self::$post, + 'insert_hooked_blocks' + ); + remove_filter( 'hooked_block_types', $filter, 10 ); + + $this->assertSame( $expected, $actual ); + } + /** * @ticket 62716 */ From 8f53c8b2cb92f8ecd4bf35afc72ffe9367d77e0b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 17:37:31 +0200 Subject: [PATCH 06/15] Use Post Content block as anchor in existing tests --- .../tests/blocks/applyBlockHooksToContent.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/blocks/applyBlockHooksToContent.php b/tests/phpunit/tests/blocks/applyBlockHooksToContent.php index 22e3c6e8dffb5..150560dbaba24 100644 --- a/tests/phpunit/tests/blocks/applyBlockHooksToContent.php +++ b/tests/phpunit/tests/blocks/applyBlockHooksToContent.php @@ -17,13 +17,14 @@ class Tests_Blocks_ApplyBlockHooksToContent extends WP_UnitTestCase { * Set up. * * @ticket 61902. + * @ticket 63287. */ public static function wpSetUpBeforeClass() { register_block_type( 'tests/hooked-block', array( 'block_hooks' => array( - 'tests/anchor-block' => 'after', + 'core/post-content' => 'after', ), ) ); @@ -79,23 +80,25 @@ public function test_apply_block_hooks_to_content_sets_theme_attribute_on_templa /** * @ticket 61902 + * @ticket 63287 */ public function test_apply_block_hooks_to_content_inserts_hooked_block() { $context = new WP_Block_Template(); - $context->content = ''; + $context->content = ''; $actual = apply_block_hooks_to_content( $context->content, $context, 'insert_hooked_blocks' ); $this->assertSame( - '', + '', $actual ); } /** * @ticket 61074 + * @ticket 63287 */ public function test_apply_block_hooks_to_content_with_context_set_to_null() { - $content = ''; + $content = ''; /* * apply_block_hooks_to_content() will fall back to the global $post object (via get_post()) @@ -106,7 +109,7 @@ public function test_apply_block_hooks_to_content_with_context_set_to_null() { $actual = apply_block_hooks_to_content( $content, null, 'insert_hooked_blocks' ); $this->assertSame( - '', + '', $actual ); } From a25d4a79dc174c524bd6179a3057f2e8c4746433 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 18:00:10 +0200 Subject: [PATCH 07/15] Move logic out of foreach loop --- src/wp-includes/blocks.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 2b9cc84b6d48d..75321035bdd05 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1130,24 +1130,24 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i * `$content` at first and we're allowed to insert it once -- but not again. */ $suppress_single_instance_blocks = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( &$block_allows_multiple_instances, $content, $context ) { - static $single_instance_blocks_present_in_content = array(); - foreach ( $hooked_block_types as $index => $hooked_block_type ) { - if ( $context instanceof WP_Post ) { - $wrapper_block_type = 'core/post-content'; - if ( 'wp_navigation' === $context->post_type ) { - $wrapper_block_type = 'core/navigation'; - } elseif ( 'wp_block' === $context->post_type ) { - $wrapper_block_type = 'core/block'; - } + if ( $context instanceof WP_Post ) { + $wrapper_block_type = 'core/post-content'; + if ( 'wp_navigation' === $context->post_type ) { + $wrapper_block_type = 'core/navigation'; + } elseif ( 'wp_block' === $context->post_type ) { + $wrapper_block_type = 'core/block'; + } - if ( - $wrapper_block_type === $anchor_block_type && - in_array( $relative_position, array( 'before', 'after' ), true ) - ) { - $hooked_block_types = array(); - } + if ( + $wrapper_block_type === $anchor_block_type && + in_array( $relative_position, array( 'before', 'after' ), true ) + ) { + return array(); } + } + static $single_instance_blocks_present_in_content = array(); + foreach ( $hooked_block_types as $index => $hooked_block_type ) { if ( ! isset( $block_allows_multiple_instances[ $hooked_block_type ] ) ) { $hooked_block_type_definition = WP_Block_Type_Registry::get_instance()->get_registered( $hooked_block_type ); From b9311858dfba2db31c86f2bde6f51b64cb8e3d0f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 18:04:28 +0200 Subject: [PATCH 08/15] Add/move comments --- src/wp-includes/blocks.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 75321035bdd05..d3ca29949ca90 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1125,11 +1125,12 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } } - /* - * We also need to cover the case where the hooked block is not present in - * `$content` at first and we're allowed to insert it once -- but not again. - */ $suppress_single_instance_blocks = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( &$block_allows_multiple_instances, $content, $context ) { + /* + * If the context is a post object, we need to avoid inserting any blocks hooked into the + * `before` and `after` positions of the temporary wrapper block that we create to wrap the content. + * See https://core.trac.wordpress.org/ticket/63287 for more details. + */ if ( $context instanceof WP_Post ) { $wrapper_block_type = 'core/post-content'; if ( 'wp_navigation' === $context->post_type ) { @@ -1146,6 +1147,10 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } } + /* + * We also need to cover the case where a hooked block with `multiple: false` is not + * present in `$content` at first and we're allowed to insert it once -- but not again. + */ static $single_instance_blocks_present_in_content = array(); foreach ( $hooked_block_types as $index => $hooked_block_type ) { if ( ! isset( $block_allows_multiple_instances[ $hooked_block_type ] ) ) { From da9bb5d7327fd68b591eac98ea0b5897f4a53918 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 18:07:32 +0200 Subject: [PATCH 09/15] Move static var declaration to start of function --- src/wp-includes/blocks.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index d3ca29949ca90..6b72b14b63b8f 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1126,6 +1126,8 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } $suppress_single_instance_blocks = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( &$block_allows_multiple_instances, $content, $context ) { + static $single_instance_blocks_present_in_content = array(); + /* * If the context is a post object, we need to avoid inserting any blocks hooked into the * `before` and `after` positions of the temporary wrapper block that we create to wrap the content. @@ -1151,7 +1153,6 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i * We also need to cover the case where a hooked block with `multiple: false` is not * present in `$content` at first and we're allowed to insert it once -- but not again. */ - static $single_instance_blocks_present_in_content = array(); foreach ( $hooked_block_types as $index => $hooked_block_type ) { if ( ! isset( $block_allows_multiple_instances[ $hooked_block_type ] ) ) { $hooked_block_type_definition = From 125db2b99e79976c80c026583f1926e8b6d687bb Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 16 Apr 2025 20:30:46 +0200 Subject: [PATCH 10/15] Rename variable --- src/wp-includes/blocks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 6b72b14b63b8f..ba186774f26c3 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1125,7 +1125,7 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } } - $suppress_single_instance_blocks = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( &$block_allows_multiple_instances, $content, $context ) { + $suppress_blocks_from_insertion = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( &$block_allows_multiple_instances, $content, $context ) { static $single_instance_blocks_present_in_content = array(); /* @@ -1179,13 +1179,13 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } return $hooked_block_types; }; - add_filter( 'hooked_block_types', $suppress_single_instance_blocks, PHP_INT_MAX, 3 ); + add_filter( 'hooked_block_types', $suppress_blocks_from_insertion, PHP_INT_MAX, 3 ); $content = traverse_and_serialize_blocks( parse_blocks( $content ), $before_block_visitor, $after_block_visitor ); - remove_filter( 'hooked_block_types', $suppress_single_instance_blocks, PHP_INT_MAX ); + remove_filter( 'hooked_block_types', $suppress_blocks_from_insertion, PHP_INT_MAX ); return $content; } From 987436a83a2020433b7c3fb382a4534f367f4428 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 17 Apr 2025 10:24:37 +0200 Subject: [PATCH 11/15] Move logic to apply_block_hooks_to_content_from_post_object --- src/wp-includes/blocks.php | 53 +++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index ba186774f26c3..bb2a4334e5018 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1125,34 +1125,12 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } } - $suppress_blocks_from_insertion = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( &$block_allows_multiple_instances, $content, $context ) { + /* + * We also need to cover the case where a hooked block with `multiple: false` is not + * present in `$content` at first and we're allowed to insert it once -- but not again. + */ + $suppress_single_instance_blocks = static function ( $hooked_block_types ) use ( &$block_allows_multiple_instances, $content, $context ) { static $single_instance_blocks_present_in_content = array(); - - /* - * If the context is a post object, we need to avoid inserting any blocks hooked into the - * `before` and `after` positions of the temporary wrapper block that we create to wrap the content. - * See https://core.trac.wordpress.org/ticket/63287 for more details. - */ - if ( $context instanceof WP_Post ) { - $wrapper_block_type = 'core/post-content'; - if ( 'wp_navigation' === $context->post_type ) { - $wrapper_block_type = 'core/navigation'; - } elseif ( 'wp_block' === $context->post_type ) { - $wrapper_block_type = 'core/block'; - } - - if ( - $wrapper_block_type === $anchor_block_type && - in_array( $relative_position, array( 'before', 'after' ), true ) - ) { - return array(); - } - } - - /* - * We also need to cover the case where a hooked block with `multiple: false` is not - * present in `$content` at first and we're allowed to insert it once -- but not again. - */ foreach ( $hooked_block_types as $index => $hooked_block_type ) { if ( ! isset( $block_allows_multiple_instances[ $hooked_block_type ] ) ) { $hooked_block_type_definition = @@ -1179,13 +1157,13 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } return $hooked_block_types; }; - add_filter( 'hooked_block_types', $suppress_blocks_from_insertion, PHP_INT_MAX, 3 ); + add_filter( 'hooked_block_types', $suppress_single_instance_blocks, PHP_INT_MAX ); $content = traverse_and_serialize_blocks( parse_blocks( $content ), $before_block_visitor, $after_block_visitor ); - remove_filter( 'hooked_block_types', $suppress_blocks_from_insertion, PHP_INT_MAX ); + remove_filter( 'hooked_block_types', $suppress_single_instance_blocks, PHP_INT_MAX ); return $content; } @@ -1270,8 +1248,25 @@ function apply_block_hooks_to_content_from_post_object( $content, $post = null, $content ); + /* + * We need to avoid inserting any blocks hooked into the `before` and `after` positions + * of the temporary wrapper block that we create to wrap the content. + * See https://core.trac.wordpress.org/ticket/63287 for more details. + */ + $suppress_blocks_from_insertion_before_and_after_wrapper_block = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( $wrapper_block_type ) { + if ( + $wrapper_block_type === $anchor_block_type && + in_array( $relative_position, array( 'before', 'after' ), true ) + ) { + return array(); + } + return $hooked_block_types; + }; + // Apply Block Hooks. + add_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX , 3); $content = apply_block_hooks_to_content( $content, $post, $callback ); + remove_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX ); // Finally, we need to remove the temporary wrapper block. $content = remove_serialized_parent_block( $content ); From 7aa3df744a4afc18f01267fc7267c05ecdbeeef6 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 17 Apr 2025 10:26:00 +0200 Subject: [PATCH 12/15] Restore original comment, function signature --- src/wp-includes/blocks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index bb2a4334e5018..e9c16ff8b9ae0 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1126,10 +1126,10 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i } /* - * We also need to cover the case where a hooked block with `multiple: false` is not - * present in `$content` at first and we're allowed to insert it once -- but not again. + * We also need to cover the case where the hooked block is not present in + * `$content` at first and we're allowed to insert it once -- but not again. */ - $suppress_single_instance_blocks = static function ( $hooked_block_types ) use ( &$block_allows_multiple_instances, $content, $context ) { + $suppress_single_instance_blocks = static function ( $hooked_block_types ) use ( &$block_allows_multiple_instances, $content ) { static $single_instance_blocks_present_in_content = array(); foreach ( $hooked_block_types as $index => $hooked_block_type ) { if ( ! isset( $block_allows_multiple_instances[ $hooked_block_type ] ) ) { From ec4e4657a0b06b717f679c1786bf8b5d20b42b6b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 17 Apr 2025 14:57:02 +0200 Subject: [PATCH 13/15] Whitespace --- 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 e9c16ff8b9ae0..9173baa3282da 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1264,7 +1264,7 @@ function apply_block_hooks_to_content_from_post_object( $content, $post = null, }; // Apply Block Hooks. - add_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX , 3); + add_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX, 3); $content = apply_block_hooks_to_content( $content, $post, $callback ); remove_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX ); From a7d5f2e9e21e1cbc1059573e84b9e94c47257098 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 18 Apr 2025 13:48:20 +0200 Subject: [PATCH 14/15] More whitespace --- 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 9173baa3282da..838cd84a19921 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1264,7 +1264,7 @@ function apply_block_hooks_to_content_from_post_object( $content, $post = null, }; // Apply Block Hooks. - add_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX, 3); + add_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX, 3 ); $content = apply_block_hooks_to_content( $content, $post, $callback ); remove_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX ); From 0c0e870fa84d1803912279cf9d69ac3a9f17f3e1 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 18 Apr 2025 13:53:37 +0200 Subject: [PATCH 15/15] Register dynamically hooked block before usage --- .../tests/blocks/applyBlockHooksToContentFromPostObject.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php index c27a3d6362976..5ff9f7323e0f3 100644 --- a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php +++ b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php @@ -97,6 +97,8 @@ public static function wpSetUpBeforeClass() { ), ) ); + + register_block_type( 'tests/dynamically-hooked-block-before-post-content' ); } /** @@ -110,6 +112,7 @@ public static function wpTearDownAfterClass() { $registry->unregister( 'tests/hooked-block' ); $registry->unregister( 'tests/hooked-block-first-child' ); $registry->unregister( 'tests/hooked-block-after-post-content' ); + $registry->unregister( 'tests/dynamically-hooked-block-before-post-content' ); } /**