render_block_context хук-фильтрWP 5.5.0

Filters the default context provided to a rendered block.

Использование

add_filter( 'render_block_context', 'wp_kama_render_block_context_filter', 10, 3 );

/**
 * Function for `render_block_context` filter-hook.
 * 
 * @param array         $context      Default context.
 * @param array         $parsed_block Block being rendered, filtered by `render_block_data`.
 * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block.
 *
 * @return array
 */
function wp_kama_render_block_context_filter( $context, $parsed_block, $parent_block ){

	// filter...
	return $context;
}
$context(массив)
Default context.
$parsed_block(массив)
Block being rendered, filtered by render_block_data.
$parent_block(WP_Block|null)
If this is a nested block, a reference to the parent block.

Список изменений

С версии 5.5.0 Введена.
С версии 5.9.0 The $parent_block parameter was added.

Где вызывается хук

render_block()
render_block_context
WP_Block::render()
render_block_context
wp-includes/blocks.php 1047
$context = apply_filters( 'render_block_context', $context, $parsed_block, $parent_block );
wp-includes/class-wp-block.php 240
$inner_block->context = apply_filters( 'render_block_context', $inner_block->context, $inner_block->parsed_block, $parent_block );

Где используется хук в WordPress

wp-includes/default-filters.php 683
add_filter( 'render_block_context', '_block_template_render_without_post_block_context' );