Returns a function that injects the theme attribute into, and hooked blocks before, a given block.
Description
The returned function can be used as $pre_callback
argument to traverse_and_serialize_block(s)
, where it will inject the theme
attribute into all Template Part blocks, and prepend the markup for any blocks hooked before
the given block and as its parent’s first_child
, respectively.
This function is meant for internal use only.
Parameters
$hooked_blocks
arrayrequired- An array of blocks hooked to another given block.
$context
WP_Block_Template|WP_Post|arrayrequired- A block template, template part,
wp_navigation
post object, or pattern that the blocks belong to. $callback
callableoptional- A function that will be called for each block to generate the markup for a given list of blocks that are hooked to it.
Default:'insert_hooked_blocks'
.Default:
'insert_hooked_blocks'
Source
/*
* Skip meta generation if post type is not set.
*/
if ( ! isset( $post->post_type ) ) {
return $post;
}
$attributes = array();
$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,
);
}
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';
}
$markup = get_comment_delimited_block_content(
$wrapper_block_type,
$attributes,
$post->post_content
);
$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.
User Contributed Notes
You must log in before being able to contribute a note or feedback.