wpseek.com
A WordPress-centric search engine for devs and theme authors



block_core_tabs_provide_context › WordPress Function

Since7.1.0
Deprecatedn/a
block_core_tabs_provide_context ( $context, $parsed_block )
Parameters: (2)
  • (array) $context Default block context.
    Required: Yes
  • (array) $parsed_block The block being rendered.
    Required: Yes
Returns:
  • (array) Modified context.
Defined at:
Codex:

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.


Source

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;
}