render_block_context
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 A representative array of the block being rendered. See WP_Block_Parser_Block. * @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)
A representative array of the block being rendered. See WP_Block_Parser_Block.
-
blockName(string)
Name of block. -
attrs(array)
Attributes from block comment delimiters. -
innerBlocks(array[])
List of inner blocks. An array of arrays that have the same structure as this one. -
innerHTML(string)
HTML from inside block comment delimiters. - innerContent(array)
List of string fragments and null markers where inner blocks were found.
-
- $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_context
wp-includes/blocks.php 2057
$context = apply_filters( 'render_block_context', $context, $parsed_block, $parent_block );
wp-includes/class-wp-block.php 497
$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/blocks/block.php 87
add_filter( 'render_block_context', $filter_block_context, 1 );
wp-includes/blocks/block.php 94
remove_filter( 'render_block_context', $filter_block_context, 1 );
wp-includes/blocks/comment-template.php 44
add_filter( 'render_block_context', $filter_block_context, 1 );
wp-includes/blocks/comment-template.php 52
remove_filter( 'render_block_context', $filter_block_context, 1 );
wp-includes/blocks/post-template.php 120
add_filter( 'render_block_context', $filter_block_context, 1 );
wp-includes/blocks/post-template.php 124
remove_filter( 'render_block_context', $filter_block_context, 1 );
wp-includes/default-filters.php 718
add_filter( 'render_block_context', '_block_template_render_without_post_block_context' );