← All changes
|
modules/editor-one/classes/menu-data-provider.php
+19
-4
4.2.3
→
4.3.0-beta3
View file →
| @@ -24,8 +24,9 @@ | ||
| 24 | 24 | private ?array $cached_level3_sidebar_data = null; |
| 25 | 25 | private ?array $cached_level4_sidebar_data = null; |
| 26 | 26 | private ?array $cached_flyout_menu_data = null; |
| 27 | 27 | private Slug_Normalizer $slug_normalizer; |
| 28 | + private array $registration_options = []; | |
| 28 | 29 | |
| 29 | 30 | public static function instance(): self { |
| 30 | 31 | if ( null === self::$instance ) { |
| 31 | 32 | self::$instance = new self(); |
| @@ -41,9 +42,13 @@ | ||
| 41 | 42 | public function get_slug_normalizer(): Slug_Normalizer { |
| 42 | 43 | return $this->slug_normalizer; |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | - public function register_menu( Menu_Item_Interface $item ): void { | |
| 46 | + public function register_menu( Menu_Item_Interface $item, array $options = [] ): void { | |
| 47 | + if ( ! empty( $options['preserve_label_casing'] ) ) { | |
| 48 | + $this->registration_options[ $item->get_slug() ]['preserve_label_casing'] = true; | |
| 49 | + } | |
| 50 | + | |
| 46 | 51 | if ( ! ( $item instanceof Menu_Item_Third_Level_Interface ) ) { |
| 47 | 52 | $this->register_level4_item( $item ); |
| 48 | 53 | return; |
| 49 | 54 | } |
| @@ -365,9 +370,9 @@ | ||
| 365 | 370 | $url = $this->resolve_item_url( $item, $item_slug ); |
| 366 | 371 | |
| 367 | 372 | return [ |
| 368 | 373 | 'slug' => $item_slug, |
| 369 | - 'label' => $this->title_case( $item->get_label() ), | |
| 374 | + 'label' => $this->format_flyout_label( $item, $item_slug ), | |
| 370 | 375 | 'url' => $url, |
| 371 | 376 | 'group_id' => '', |
| 372 | 377 | 'priority' => $this->get_item_priority( $item ), |
| 373 | 378 | 'has_divider_before' => $is_first, |
| @@ -401,9 +406,9 @@ | ||
| 401 | 406 | $is_third_party_parent = Menu_Config::THIRD_PARTY_GROUP_ID === $item->get_group_id(); |
| 402 | 407 | |
| 403 | 408 | return [ |
| 404 | 409 | 'slug' => $item_slug, |
| 405 | - 'label' => $this->title_case( $item->get_label() ), | |
| 410 | + 'label' => $this->format_flyout_label( $item, $item_slug ), | |
| 406 | 411 | 'url' => $this->resolve_flyout_item_url( $item, $item_slug ), |
| 407 | 412 | 'icon' => $item->get_icon(), |
| 408 | 413 | 'group_id' => $group_id, |
| 409 | 414 | 'priority' => $this->get_item_priority( $item ), |
| @@ -480,9 +485,9 @@ | ||
| 480 | 485 | $url = $this->resolve_item_url( $item, $item_slug ); |
| 481 | 486 | |
| 482 | 487 | $groups[ $group_id ]['items'][] = [ |
| 483 | 488 | 'slug' => $item_slug, |
| 484 | - 'label' => $this->title_case( $item->get_label() ), | |
| 489 | + 'label' => $this->format_flyout_label( $item, $item_slug ), | |
| 485 | 490 | 'url' => $url, |
| 486 | 491 | 'priority' => $this->get_item_priority( $item ), |
| 487 | 492 | 'event_id' => $this->resolve_event_id( $item, $item_slug ), |
| 488 | 493 | ]; |
| @@ -566,8 +571,18 @@ | ||
| 566 | 571 | $event_id = preg_replace( '/[?#].*$/', '', $event_id ); |
| 567 | 572 | $event_id = str_replace( [ '-', ' ' ], '_', $event_id ); |
| 568 | 573 | |
| 569 | 574 | return strtolower( $event_id ); |
| 575 | + } | |
| 576 | + | |
| 577 | + private function format_flyout_label( Menu_Item_Interface $item, string $item_slug ): string { | |
| 578 | + $label = $item->get_label(); | |
| 579 | + | |
| 580 | + if ( ! empty( $this->registration_options[ $item_slug ]['preserve_label_casing'] ) ) { | |
| 581 | + return $label; | |
| 582 | + } | |
| 583 | + | |
| 584 | + return $this->title_case( $label ); | |
| 570 | 585 | } |
| 571 | 586 | |
| 572 | 587 | private function title_case( string $text ): string { |
| 573 | 588 | if ( function_exists( 'mb_convert_case' ) ) { |