From b440a4f84f1666eccb7a890da3b18b3d6a8006d7 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 20 Feb 2024 09:27:06 +0000 Subject: [PATCH] Block Hooks: Introduce a new `hooked_block` filter. This is a counterpart to the dynamic `hooked_block_{$block_type}` filter introduced in [57354], which makes it easier to modify all hooked blocks prior to insertion. Also adds the hooked block type as an additional argument to both filters for consistency. Props bernhard-reiter, swissspidy. Fixes #60574. Built from https://develop.svn.wordpress.org/trunk@57660 git-svn-id: http://core.svn.wordpress.org/trunk@57161 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 25 ++++++++++++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 7931061086..81207da795 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -895,20 +895,35 @@ function insert_hooked_blocks( &$parsed_anchor_block, $relative_position, $hooke /** * Filters the parsed block array for a given hooked block. * - * The dynamic portion of the hook name, `$hooked_block_type`, refers to the block type name of the specific hooked block. - * * @since 6.5.0 * * @param array $parsed_hooked_block The parsed block array for the given hooked block type. + * @param string $hooked_block_type The hooked block type name. * @param string $relative_position The relative position of the hooked block. * @param array $parsed_anchor_block The anchor block, in parsed block array format. * @param WP_Block_Template|WP_Post|array $context The block template, template part, `wp_navigation` post type, * or pattern that the anchor block belongs to. */ - $parsed_hooked_block = apply_filters( "hooked_block_{$hooked_block_type}", $parsed_hooked_block, $relative_position, $parsed_anchor_block, $context ); + $parsed_hooked_block = apply_filters( 'hooked_block', $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context ); - // It's possible that the `hooked_block_{$hooked_block_type}` filter returned a block of a different type, - // so we explicitly look for the original `$hooked_block_type` in the `ignoredHookedBlocks` metadata. + /** + * Filters the parsed block array for a given hooked block. + * + * The dynamic portion of the hook name, `$hooked_block_type`, refers to the block type name of the specific hooked block. + * + * @since 6.5.0 + * + * @param array $parsed_hooked_block The parsed block array for the given hooked block type. + * @param string $hooked_block_type The hooked block type name. + * @param string $relative_position The relative position of the hooked block. + * @param array $parsed_anchor_block The anchor block, in parsed block array format. + * @param WP_Block_Template|WP_Post|array $context The block template, template part, `wp_navigation` post type, + * or pattern that the anchor block belongs to. + */ + $parsed_hooked_block = apply_filters( "hooked_block_{$hooked_block_type}", $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context ); + + // It's possible that the filter returned a block of a different type, so we explicitly + // look for the original `$hooked_block_type` in the `ignoredHookedBlocks` metadata. if ( ! isset( $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) || ! in_array( $hooked_block_type, $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'], true ) diff --git a/wp-includes/version.php b/wp-includes/version.php index f4af152088..37448933df 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-beta1-57659'; +$wp_version = '6.5-beta1-57660'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.