From 859a39a5f9ccc51f3110ffd3c76d2da3751ba66e Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Wed, 4 Dec 2024 12:07:17 +0000 Subject: [PATCH] Block Hooks: Fix context in `update_ignored_hooked_blocks_postmeta`. Ensure that the `$context` arg passed from `update_ignored_hooked_blocks_postmeta` to `apply_block_hooks_to_content` (and from there, to filters such as `hooked_block_types` and `hooked_block`) has the correct type (`WP_Post`). Filters hooked to `hooked_block_types` etc can typically include checks that conditionally insert a hooked block depending on `$context`. Prior to this changeset, a check like `if ( $context instanceof WP_Post )` would incorrectly fail, as `$context` would be a `stdClass` instance rather than a `WP_Post`. As a consequence, a hooked block inside of a Navigation post object that was modified by the user would not be marked as ignored by `update_ignored_hooked_blocks_postmeta`, and thus be erroneosly re-inserted by the Block Hooks algorithm. Props bernhard-reiter. Fixes #62639. Built from https://develop.svn.wordpress.org/trunk@59482 git-svn-id: http://core.svn.wordpress.org/trunk@58868 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 1 + wp-includes/version.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 9d8f4bfaf9..94c4dfa43a 100644 --- a/wp-includes/blocks.php +++ b/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]; diff --git a/wp-includes/version.php b/wp-includes/version.php index ae68572255..9b5c292d28 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59481'; +$wp_version = '6.8-alpha-59482'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.