Exceptions
1 year ago
PaymentsProviders
4 days ago
SettingsUIPages
1 month ago
LegacySettingsPageAdapter.php
4 days ago
Payments.php
4 months ago
PaymentsController.php
11 months ago
PaymentsProviders.php
2 months ago
PaymentsRestController.php
3 months ago
RegisteredSettingsSectionAdapter.php
3 weeks ago
SettingsSectionNavigation.php
4 days ago
SettingsUIPageInterface.php
1 month ago
SettingsUIRequestContext.php
4 days ago
SettingsUISchema.php
3 weeks ago
Utils.php
3 months ago
SettingsSectionNavigation.php
58 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Settings UI section navigation builder. |
| 4 | */ |
| 5 | |
| 6 | declare( strict_types=1 ); |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Internal\Admin\Settings; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | /** |
| 13 | * Builds section navigation entries for the Settings UI shell. |
| 14 | * |
| 15 | * @since 11.0.0 |
| 16 | */ |
| 17 | final class SettingsSectionNavigation { |
| 18 | |
| 19 | /** |
| 20 | * Build the default settings section navigation for the settings UI shell. |
| 21 | * |
| 22 | * Lists every section of the settings page, linking back through the classic |
| 23 | * settings URLs. Returns an empty array for pages with fewer than two sections. |
| 24 | * |
| 25 | * @since 11.0.0 |
| 26 | * |
| 27 | * @param \WC_Settings_Page $settings_page Settings page to build the navigation for. |
| 28 | * @param string $current_section Current section id. Empty string means the default section. |
| 29 | * @return array<int, array{id: string, label: string, href: string, active: bool}> |
| 30 | */ |
| 31 | public static function build_default( \WC_Settings_Page $settings_page, string $current_section ): array { |
| 32 | $sections = $settings_page->get_sections(); |
| 33 | if ( empty( $sections ) || 1 === count( $sections ) ) { |
| 34 | return array(); |
| 35 | } |
| 36 | |
| 37 | $navigation = array(); |
| 38 | foreach ( $sections as $id => $label ) { |
| 39 | $section_id = (string) $id; |
| 40 | $navigation[] = array( |
| 41 | 'id' => '' === $section_id ? 'default' : $section_id, |
| 42 | 'label' => wp_strip_all_tags( html_entity_decode( (string) $label, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) ), |
| 43 | 'href' => add_query_arg( |
| 44 | array( |
| 45 | 'page' => 'wc-settings', |
| 46 | 'tab' => sanitize_title( $settings_page->get_id() ), |
| 47 | 'section' => sanitize_title( $section_id ), |
| 48 | ), |
| 49 | admin_url( 'admin.php' ) |
| 50 | ), |
| 51 | 'active' => $current_section === $section_id, |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | return $navigation; |
| 56 | } |
| 57 | } |
| 58 |