From 6f2e9a312f703fa4d7b7c1f94470c8787d959edd Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 3 Dec 2024 15:19:28 +0100 Subject: [PATCH 1/2] Fix bug --- src/wp-includes/blocks.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 9d8f4bfaf9845..94c4dfa43afb6 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1217,6 +1217,7 @@ function update_ignored_hooked_blocks_postmeta( $post ) { $existing_post = get_post( $post->ID ); // Merge the existing post object with the updated post object to pass to the block hooks algorithm for context. $context = (object) array_merge( (array) $existing_post, (array) $post ); + $context = new WP_Post( $context ); // Convert to WP_Post object. $serialized_block = apply_block_hooks_to_content( $markup, $context, 'set_ignored_hooked_blocks_metadata' ); $root_block = parse_blocks( $serialized_block )[0]; From 0385b085d782e3d8a6b00afbbe4650689ce3ff74 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 3 Dec 2024 17:49:14 +0100 Subject: [PATCH 2/2] Add test coverage --- .../updateIgnoredHookedBlocksPostMeta.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/phpunit/tests/blocks/updateIgnoredHookedBlocksPostMeta.php b/tests/phpunit/tests/blocks/updateIgnoredHookedBlocksPostMeta.php index 7b0a830dd52dd..18b5eff08ba79 100644 --- a/tests/phpunit/tests/blocks/updateIgnoredHookedBlocksPostMeta.php +++ b/tests/phpunit/tests/blocks/updateIgnoredHookedBlocksPostMeta.php @@ -193,4 +193,31 @@ public function test_update_ignored_hooked_blocks_postmeta_dont_modify_if_no_pos 'Post content did not match the original markup.' ); } + + /** + * @ticket 62639 + */ + public function test_update_ignored_hooked_blocks_postmeta_sets_correct_context_type() { + $action = new MockAction(); + add_filter( 'hooked_block_types', array( $action, 'filter' ), 10, 4 ); + + $original_markup = ''; + $post = new stdClass(); + $post->ID = self::$navigation_post->ID; + $post->post_content = $original_markup; + $post->post_type = 'wp_navigation'; + + $post = update_ignored_hooked_blocks_postmeta( $post ); + + $args = $action->get_args(); + $contexts = array_column( $args, 3 ); + + foreach ( $contexts as $context ) { + $this->assertInstanceOf( + WP_Post::class, + $context, + 'The context passed to the hooked_block_types filter is not a WP_Post instance.' + ); + } + } }