block_core_tabs_provide_context()
Filter to provide tabs list context to core/tabs and core/tab-list blocks. It is more performant to do this here, once, rather than in the tabs render and tabs context filters. In this way core/tabs is both a provider and a consumer of the core/tabs-list context.
No Hooks.
Returns
array. Modified context.
Usage
block_core_tabs_provide_context( $context, $parsed_block ): array;
- $context(array) (required)
- Default block context.
- $parsed_block(array) (required)
- The block being rendered.
Changelog
| Since 7.1.0 | Introduced. |
block_core_tabs_provide_context() block core tabs provide context code WP 7.1
function block_core_tabs_provide_context( array $context, array $parsed_block ): array {
if ( 'core/tabs' === $parsed_block['blockName'] ) {
// Generate a unique ID for the tabs instance first, so it can be used
// to derive stable tab IDs.
$tabs_id = $parsed_block['attrs']['anchor'] ?? wp_unique_id( 'tabs_' );
$tabs_list = block_core_tabs_generate_tabs_list( $parsed_block['innerBlocks'] ?? array(), $tabs_id );
$context['core/tabs-list'] = $tabs_list;
$context['core/tabs-id'] = $tabs_id;
}
return $context;
}