wp-includes/blocks.php:1192Run the Block Hooks algorithm on a post object's content.
$contentstring$postWP_Post|nulloptionalnull$callbackcallableoptional'insert_hooked_blocks'stringfunction apply_block_hooks_to_content_from_post_object( $content, $post = null, $callback = 'insert_hooked_blocks' ) { // Default to the current post if no context is provided. if ( null === $post ) { $post = get_post(); } if ( ! $post instanceof WP_Post ) { return apply_block_hooks_to_content( $content, $post, $callback ); } /* * If the content was created using the classic editor or using a single Classic block * (`core/freeform`), it might not contain any block markup at all. * However, we still might need to inject hooked blocks in the first child or last child * positions of the parent block. To be able to apply the Block Hooks algorithm, we wrap * the content in a `core/freeform` wrapper block. */ if ( ! has_blocks( $content ) ) { $original_content = $content; $content_wrapped_in_classic_block = get_comment_delimited_block_content( 'core/freeform', array(), $content ); $content = $content_wrapped_in_classic_block; } $attributes = array(); // If context is a post object, `ignoredHookedBlocks` information is stored in its post meta. $ignored_hooked_blocks = get_post_meta( $post->ID, '_wp_ignored_hooked_blocks', true ); if ( ! empty( $ignored_hooked_blocks ) ) { $ignored_hooked_blocks = json_decode( $ignored_hooked_blocks, true ); $attributes['metadata'] = array( 'ignoredHookedBlocks' => $ignored_hooked_blocks, ); } /* * We need to wrap the content in a temporary wrapper block with that metadata * so the Block Hooks algorithm can insert blocks that are hooked as first or last child * of the wrapper block. * To that end, we need to determine the wrapper block type based on the post type. */ if ( 'wp_navigation' === $post->post_type ) { $wrapper_block_type = 'core/navigation'; } elseif ( 'wp_block' === $post->post_type ) { $wrapper_block_type = 'core/block'; } else { $wrapper_block_type = 'core/post-content'; } $content = get_comment_delimited_block_content( $wrapper_block_type, $attributes, $content ); /* * We need to avoid inserting any blocks hooked into the `before` and `after` positions * of the temporary wrapper block that we create to wrap the content. * See https://core.trac.wordpress.org/ticket/63287 for more details. */ $suppress_blocks_from_insertion_before_and_after_wrapper_block = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( $wrapper_block_type ) { if ( $wrapper_block_type === $anchor_block_type && in_array( $relative_position, array( 'before', 'after' ), true ) ) { return array(); } return $hooked_block_types; }; // Apply Block Hooks. add_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX, 3 ); $content = apply_block_hooks_to_content( $content, $post, $callback ); remove_filter( 'hooked_block_types', $suppress_blocks_from_insertion_before_and_after_wrapper_block, PHP_INT_MAX );Introduced in 6.8.0. One change between 6.8.8 and 7.1.0.
Signature, return type and hooks compared across 4 parsed releases.
$ignored_hooked_blocks_at_root added.verified against sourcesrc/wp-includes/blocks.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.