Adds a list of hooked block types to an anchor block’s ignored hooked block types.
Description
This function is meant for internal use only.
Parameters
$parsed_anchor_block
arrayrequired- The anchor block, in parsed block array format.
$relative_position
stringrequired- The relative position of the hooked blocks.
Can be one of'before'
,'after'
,'first_child'
, or'last_child'
. $hooked_blocks
arrayrequired- An array of hooked block types, grouped by anchor block and relative position.
$context
WP_Block_Template|WP_Post|arrayrequired- The block template, template part, or pattern that the anchor block belongs to.
Source
function set_ignored_hooked_blocks_metadata( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) {
$anchor_block_type = $parsed_anchor_block['blockName'];
$hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
: array();
/** 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 );
if ( empty( $hooked_block_types ) ) {
return '';
}
foreach ( $hooked_block_types as $index => $hooked_block_type ) {
$parsed_hooked_block = array(
'blockName' => $hooked_block_type,
'attrs' => array(),
'innerBlocks' => array(),
'innerContent' => array(),
);
/** This filter is documented in wp-includes/blocks.php */
$parsed_hooked_block = apply_filters( 'hooked_block', $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context );
/** This filter is documented in wp-includes/blocks.php */
$parsed_hooked_block = apply_filters( "hooked_block_{$hooked_block_type}", $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context );
if ( null === $parsed_hooked_block ) {
unset( $hooked_block_types[ $index ] );
}
}
$previously_ignored_hooked_blocks = isset( $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] )
? $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks']
: array();
$parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array_unique(
array_merge(
$previously_ignored_hooked_blocks,
$hooked_block_types
)
);
// Markup for the hooked blocks has already been created (in `insert_hooked_blocks`).
return '';
}
Hooks
- apply_filters( ‘hooked_block’,
array|null $parsed_hooked_block ,string $hooked_block_type ,string $relative_position ,array $parsed_anchor_block ,WP_Block_Template|WP_Post|array $context ) Filters the parsed block array for a given hooked block.
- apply_filters( ‘hooked_block_types’,
string[] $hooked_block_types ,string $relative_position ,string $anchor_block_type ,WP_Block_Template|WP_Post|array $context ) Filters the list of hooked block types for a given anchor block type and relative position.
- apply_filters( “hooked_block_{$hooked_block_type}”,
array|null $parsed_hooked_block ,string $hooked_block_type ,string $relative_position ,array $parsed_anchor_block ,WP_Block_Template|WP_Post|array $context ) Filters the parsed block array for a given hooked block.
Changelog
Version | Description |
---|---|
6.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.