@@ -1196,6 +1196,7 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i
11961196 * of the block that corresponds to the post type are handled correctly.
11971197 *
11981198 * @since 6.8.0
1199+ * @since 7.0.0 Added the `$ignored_hooked_blocks_at_root` parameter.
11991200 * @access private
12001201 *
12011202 * @param string $content Serialized content.
@@ -1205,9 +1206,17 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i
12051206 * @param callable $callback A function that will be called for each block to generate
12061207 * the markup for a given list of blocks that are hooked to it.
12071208 * Default: 'insert_hooked_blocks'.
1209+ * @param array|null $ignored_hooked_blocks_at_root A reference to an array that will be populated
1210+ * with the ignored hooked blocks at the root level.
1211+ * Default: `null`.
12081212 * @return string The serialized markup.
12091213 */
1210- function apply_block_hooks_to_content_from_post_object ( $ content , $ post = null , $ callback = 'insert_hooked_blocks ' ) {
1214+ function apply_block_hooks_to_content_from_post_object (
1215+ $ content ,
1216+ $ post = null ,
1217+ $ callback = 'insert_hooked_blocks ' ,
1218+ &$ ignored_hooked_blocks_at_root = null
1219+ ) {
12111220 // Default to the current post if no context is provided.
12121221 if ( null === $ post ) {
12131222 $ post = get_post ();
@@ -1287,6 +1296,16 @@ function apply_block_hooks_to_content_from_post_object( $content, $post = null,
12871296 $ content = apply_block_hooks_to_content ( $ content , $ post , $ callback );
12881297 remove_filter ( 'hooked_block_types ' , $ suppress_blocks_from_insertion_before_and_after_wrapper_block , PHP_INT_MAX );
12891298
1299+ if ( null !== $ ignored_hooked_blocks_at_root ) {
1300+ // Check wrapper block's metadata for ignored hooked blocks at the root level, and populate the reference parameter if needed.
1301+ $ wrapper_block_markup = extract_serialized_parent_block ( $ content );
1302+ $ wrapper_block = parse_blocks ( $ wrapper_block_markup )[0 ];
1303+
1304+ if ( ! empty ( $ wrapper_block ['attrs ' ]['metadata ' ]['ignoredHookedBlocks ' ] ) ) {
1305+ $ ignored_hooked_blocks_at_root = $ wrapper_block ['attrs ' ]['metadata ' ]['ignoredHookedBlocks ' ];
1306+ }
1307+ }
1308+
12901309 // Finally, we need to remove the temporary wrapper block.
12911310 $ content = remove_serialized_parent_block ( $ content );
12921311
@@ -1449,6 +1468,7 @@ function insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata( &$parsed_a
14491468 *
14501469 * @since 6.6.0
14511470 * @since 6.8.0 Support non-`wp_navigation` post types.
1471+ * @since 7.0.0 Set `_wp_ignored_hooked_blocks` meta in the response for blocks hooked at the root level.
14521472 *
14531473 * @param WP_REST_Response $response The response object.
14541474 * @param WP_Post $post Post object.
@@ -1459,12 +1479,18 @@ function insert_hooked_blocks_into_rest_response( $response, $post ) {
14591479 return $ response ;
14601480 }
14611481
1482+ $ ignored_hooked_blocks_at_root = array ();
14621483 $ response ->data ['content ' ]['raw ' ] = apply_block_hooks_to_content_from_post_object (
14631484 $ response ->data ['content ' ]['raw ' ],
14641485 $ post ,
1465- 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata '
1486+ 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata ' ,
1487+ $ ignored_hooked_blocks_at_root
14661488 );
14671489
1490+ if ( ! empty ( $ ignored_hooked_blocks_at_root ) ) {
1491+ $ response ->data ['meta ' ]['_wp_ignored_hooked_blocks ' ] = wp_json_encode ( $ ignored_hooked_blocks_at_root );
1492+ }
1493+
14681494 // If the rendered content was previously empty, we leave it like that.
14691495 if ( empty ( $ response ->data ['content ' ]['rendered ' ] ) ) {
14701496 return $ response ;
0 commit comments