block_core_tabs_render_block_callback()
Render callback for core/tabs.
No Hooks.
Returns
string. Updated HTML.
Usage
block_core_tabs_render_block_callback( $attributes, $content, $block ): string;
- $attributes(array) (required)
- Block attributes.
- $content(string) (required)
- Block content.
- $block(WP_Block) (required)
- WP_Block instance.
Changelog
| Since 7.1.0 | Introduced. |
block_core_tabs_render_block_callback() block core tabs render block callback code WP 7.1
function block_core_tabs_render_block_callback( array $attributes, string $content, \WP_Block $block ): string {
$active_tab_index = $attributes['activeTabIndex'] ?? 0;
$tabs_list = $block->context['core/tabs-list'] ?? array();
$tabs_id = $block->context['core/tabs-id'] ?? null;
if ( empty( $tabs_id ) ) {
// If malformed tabs, return early to avoid errors.
return '';
}
$tag_processor = new WP_HTML_Tag_Processor( $content );
$tag_processor->next_tag( array( 'class_name' => 'wp-block-tabs' ) );
$tag_processor->set_attribute( 'data-wp-interactive', 'core/tabs' );
$tag_processor->set_attribute(
'data-wp-context',
wp_json_encode(
array(
'tabsId' => $tabs_id,
'activeTabIndex' => $active_tab_index,
)
)
);
$tag_processor->set_attribute( 'data-wp-init', 'callbacks.onTabsInit' );
$tag_processor->set_attribute( 'data-wp-on--keydown', 'actions.handleTabKeyDown' );
$output = $tag_processor->get_updated_html();
/**
* Builds a client side state for just this tabs instance, so each
* core/tabs block manages its own state, like context.
*/
wp_interactivity_state(
'core/tabs',
array(
$tabs_id => $tabs_list,
)
);
return $output;
}