make_after_block_visitor()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
make_after_block_visitor( array $hooked_blocks, WP_Block_Template|WP_Post|array $context, callable $callback = 'insert_hooked_blocks' ): callable
Описание
Возвращаемую функцию можно передать как аргумент $post_callback в traverse_and_serialize_block(s), где она добавит разметку любых блоков, подключённых после заданного блока, а также в качестве last_child его родителя соответственно.
Эта функция предназначена только для внутреннего использования.
Оригинал (английский)
The returned function can be used as $post_callback argument to traverse_and_serialize_block(s), where it will append the markup for any blocks hooked after the given block and as its parent’s last_child, respectively.
This function is meant for internal use only.
Параметры
$hooked_blocks
array
обязательный
$context
WP_Block_Template|WP_Post|array
обязательный
$callback
callable
необязательный
= 'insert_hooked_blocks'
Возвращаемое значение
callable
Исходный код
wp-includes/blocks.php:1598
function make_after_block_visitor( $hooked_blocks, $context, $callback = 'insert_hooked_blocks' ) {
/**
* Injects hooked blocks after the given block, and returns the serialized markup.
*
* Append the markup for any blocks hooked `after` the given block and as its parent's
* `last_child`, respectively, to the serialized markup for the given block.
*
* @param array $block The block to inject the hooked blocks after. Passed by reference.
* @param array $parent_block The parent block of the given block. Passed by reference. Default null.
* @param array $next The next sibling block of the given block. Default null.
* @return string The serialized markup for the given block, with the markup for any hooked blocks appended to it.
*/
return function ( &$block, &$parent_block = null, $next = null ) use ( $hooked_blocks, $context, $callback ) {
$markup = call_user_func_array(
$callback,
array( &$block, 'after', $hooked_blocks, $context )
);
if ( $parent_block && ! $next ) {
// Candidate for last-child insertion.
$markup .= call_user_func_array(
$callback,
array( &$parent_block, 'last_child', $hooked_blocks, $context )
);
}
return $markup;
};
}
История изменений
| Версия | Описание |
|---|---|
| 6.5.0 | Added $callback argument. |
| 6.4.0 | Introduced. |

