context['core/tabs-list'] ?? array(); if ( empty( $tabs_list ) ) { return $content; } // Re-render each tabs-menu-item with per-item context (index, id, label). // Match by anchor so the correct tab is found even when the two lists // are in different orders. $buttons_html = ''; foreach ( $block->parsed_block['innerBlocks'] ?? array() as $parsed_menu_item ) { if ( 'core/tabs-menu-item' !== ( $parsed_menu_item['blockName'] ?? '' ) ) { continue; } // Find the tab anchor from the menu item anchor (e.g. "tab-1-button" → "tab-1"). $menu_item_anchor = $parsed_menu_item['attrs']['anchor'] ?? ''; $tab_anchor = preg_replace( '/-button$/', '', $menu_item_anchor ); // Find the matching tab in $tabs_list by id. $tab = null; $tab_index = 0; foreach ( $tabs_list as $index => $candidate ) { if ( ( $candidate['id'] ?? '' ) === $tab_anchor ) { $tab = $candidate; $tab_index = $index; break; } } // Skip menu items with no matching tab. if ( null === $tab ) { continue; } $item_context = array_merge( $block->context, array( 'core/tabs-menu-item-index' => $tab_index, 'core/tabs-menu-item-id' => $tab['id'] ?? '', 'core/tabs-menu-item-label' => $tab['label'] ?? '', ) ); $menu_item_block = new WP_Block( $parsed_menu_item, $item_context ); $buttons_html .= $menu_item_block->render(); } // Rebuild the wrapper using get_block_wrapper_attributes(). $wrapper_attributes = get_block_wrapper_attributes( array( 'role' => 'tablist' ) ); return sprintf( '