render_block_context filter-hookWP 5.5.0

Filters the default context provided to a rendered block.

Usage

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(array)
Default context.
$parsed_block(array)
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.

Changelog

Since 5.5.0 Introduced.
Since 5.9.0 The $parent_block parameter was added.

Where the hook is called

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

Where the hook is used in WordPress

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