| @@ -10,36 +10,19 @@ | ||
| 10 | 10 | * |
| 11 | 11 | * @since 7.0.0 |
| 12 | 12 | * |
| 13 | 13 | * @param array $attributes Block attributes. |
| 14 | -* @param array $attributes Block attributes. | |
| 15 | -* @param string $content Block content. | |
| 16 | -* @param \WP_Block $block Block instance. | |
| 14 | + * @param string $content Block content. | |
| 17 | 15 | * |
| 18 | 16 | * @return string Updated HTML. |
| 19 | 17 | */ |
| 20 | -function gutenberg_block_core_tab_render( array $attributes, string $content, \WP_Block $block ): string { | |
| 21 | - $tabs_id = $block->context['core/tabs-id'] ?? ''; | |
| 22 | - | |
| 23 | - static $tab_counters = array(); | |
| 24 | - | |
| 25 | - if ( ! isset( $tab_counters[ $tabs_id ] ) ) { | |
| 26 | - $tab_counters[ $tabs_id ] = 0; | |
| 27 | - } | |
| 28 | - | |
| 29 | - $tab_index = $tab_counters[ $tabs_id ]; | |
| 30 | - ++$tab_counters[ $tabs_id ]; | |
| 31 | - | |
| 18 | +function gutenberg_block_core_tab_render( array $attributes, string $content ): string { | |
| 32 | 19 | $tag_processor = new WP_HTML_Tag_Processor( $content ); |
| 33 | 20 | $tag_processor->next_tag( array( 'class_name' => 'wp-block-tab' ) ); |
| 34 | - | |
| 35 | - // Use the user's custom anchor if present, otherwise fall back to | |
| 36 | - // the generated position-based ID. | |
| 37 | 21 | $tab_id = (string) $tag_processor->get_attribute( 'id' ); |
| 22 | + // If no id, generate a unique one | |
| 38 | 23 | if ( empty( $tab_id ) ) { |
| 39 | - $tab_id = ! empty( $tabs_id ) | |
| 40 | - ? $tabs_id . '-tab-' . $tab_index | |
| 41 | - : 'tab-' . $tab_index; | |
| 24 | + $tab_id = sanitize_title( $attributes['label'] ); | |
| 42 | 25 | $tag_processor->set_attribute( 'id', $tab_id ); |
| 43 | 26 | } |
| 44 | 27 | |
| 45 | 28 | /** |