diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 591a7971ca..431e2b0153 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -757,6 +757,38 @@ 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. + * + * 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. + * @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(); + } + + 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; + + 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 +845,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 +858,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 +906,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 +920,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/wp-includes/version.php b/wp-includes/version.php index 3b6a8653cc..5cddc620db 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-alpha-57155'; +$wp_version = '6.5-alpha-57157'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.