функция
since 6.5.0
insert_hooked_blocks()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
insert_hooked_blocks( array $parsed_anchor_block, string $relative_position, array $hooked_blocks, WP_Block_Template|WP_Post|array $context ): string
Описание
Возвращает разметку для блоков, прикреплённых к заданному якорному блоку в определённой относительной позиции.
Параметры
$parsed_anchor_block
array
обязательный
Якорный блок в формате массива разобранного блока.
$relative_position
string
обязательный
Относительная позиция прикреплённых блоков.
Может быть одним из 'before', 'after', 'first_child' или 'last_child'.
$hooked_blocks
array
обязательный
Массив типов прикреплённых блоков, сгруппированных по якорному блоку и относительной позиции.
$context
WP_Block_Template|WP_Post|array
обязательный
Шаблон блока, часть шаблона или паттерн, которому принадлежит якорный блок.
Возвращаемое значение
string
Исходный код
wp-includes/blocks.php:948
function insert_hooked_blocks( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) {
$anchor_block_type = $parsed_anchor_block['blockName'];
$hooked_block_types = isset( $anchor_block_type, $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
: array();
/**
* Filters the list of hooked block types for a given anchor block type and relative position.
*
* @since 6.4.0
*
* @param string[] $hooked_block_types The list of hooked block types.
* @param string $relative_position The relative position of the hooked blocks.
* Can be one of 'before', 'after', 'first_child', or 'last_child'.
* @param string $anchor_block_type The anchor block type.
* @param WP_Block_Template|WP_Post|array $context The block template, template part, post object,
* or pattern that the anchor block belongs to.
*/
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
$markup = '';
foreach ( $hooked_block_types as $hooked_block_type ) {
$parsed_hooked_block = array(
'blockName' => $hooked_block_type,
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '',
'innerContent' => array(),
);
/**
* Filters the parsed block array for a given hooked block.
*
* @since 6.5.0
*
* @param array|null $parsed_hooked_block The parsed block array for the given hooked block type, or null to suppress the block.
* @param string $hooked_block_type The hooked block type name.
* @param string $relative_position The relative position of the hooked block.
* @param array $parsed_anchor_block The anchor block, in parsed block array format.
* @param WP_Block_Template|WP_Post|array $context The block template, template part, post object,
* or pattern that the anchor block belongs to.
*/
$parsed_hooked_block = apply_filters( 'hooked_block', $parsed_hooked_block, $hooked_block_type, $relative_position, $parsed_anchor_block, $context );
/**
* Filters the parsed block array for a given hooked block.
*
* The dynamic portion of the hook name, `$hooked_block_type`, refers to the block type name of the specific hooked block.
*
* @since 6.5.0
*
* @param array|null $parsed_hooked_block The parsed block array for the given hooked block type, or null to suppress the block.
* @param string $hooked_block_type The hooked block type name.
* @param string $relative_position The relative position of the hooked block.
* @param array $parsed_anchor_block The anchor block, in parsed block array format.
* @param WP_Block_Template|WP_Post|array $context The block template, template part, post object,
* or pattern that the anchor block belongs to.
*/
$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 ) {
continue;
}
// It's possible that the filter returned a block of a different type, so we explicitly
// look for the original `$hooked_block_type` in the `ignoredHookedBlocks` metadata.
if (
! isset( $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ||
! in_array( $hooked_block_type, $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'], true )
) {
$markup .= serialize_block( $parsed_hooked_block );
}
}
return $markup;
}
История изменений
| Версия | Описание |
|---|---|
| 6.5.0 | Introduced. |

