| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Tab List Block 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Render callback for core/tab-list. 10 * 11 * Injects IAPI directives into the saved button HTML. The buttons already 12 * carry color/border/padding styles from save.js; this callback adds 13 * tab-specific attributes (id, aria-controls, context) and interactivity 14 * directives using data from the tabs-list context. 15 * 16 * @since 7.1.0 17 * 18 * @param array $attributes Block attributes. 19 * @param string $content Block content (rendered buttons from save.js). 20 * @param \WP_Block $block WP_Block instance. 21 * 22 * @return string Updated HTML. 23 */ 24 function block_core_tab_list_render_callback( array $attributes, string $content, \WP_Block $block ): string { 25 $tabs_list = $block->context['core/tabs-list'] ?? array(); 26 $aria_label = empty( $attributes['ariaLabel'] ) ? __( 'Tabbed content' ) : wp_strip_all_tags( $attributes['ariaLabel'] ); 27 28 $tag_processor = new WP_HTML_Tag_Processor( $content ); 29 if ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-tab-list' ) ) ) { 30 $tag_processor->set_attribute( 'aria-label', $aria_label ); 31 } 32 33 if ( empty( $tabs_list ) ) { 34 return $tag_processor->get_updated_html(); 35 } 36 37 $tab_index = 0; 38 39 while ( $tag_processor->next_tag( 'button' ) ) { 40 $tab_id = $tabs_list[ $tab_index ] ?? null; 41 42 if ( null === $tab_id ) { 43 break; 44 } 45 46 $tag_processor->set_attribute( 'id', 'tab__' . $tab_id ); 47 $tag_processor->set_attribute( 'aria-controls', $tab_id ); 48 $tag_processor->set_attribute( 'data-wp-on--click', 'actions.handleTabClick' ); 49 $tag_processor->set_attribute( 'data-wp-on--keydown', 'actions.handleTabKeyDown' ); 50 $tag_processor->set_attribute( 'data-wp-bind--aria-selected', 'state.isActiveTab' ); 51 $tag_processor->set_attribute( 'data-wp-bind--tabindex', 'state.tabIndexAttribute' ); 52 $tag_processor->set_attribute( 53 'data-wp-context', 54 wp_json_encode( array( 'tabIndex' => $tab_index ) ) 55 ); 56 57 ++$tab_index; 58 } 59 60 return $tag_processor->get_updated_html(); 61 } 62 63 /** 64 * Registers the `core/tab-list` block on the server. 65 * 66 * @since 7.1.0 67 */ 68 function register_block_core_tab_list() { 69 register_block_type_from_metadata( 70 __DIR__ . '/tab-list', 71 array( 72 'render_callback' => 'block_core_tab_list_render_callback', 73 ) 74 ); 75 } 76 add_action( 'init', 'register_block_core_tab_list' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Jul 15 08:20:16 2026 | Cross-referenced by PHPXref |