← All changes
|
modules/editor-one/classes/menu-data-provider.php
+39
-260
4.2.1
→
3.34.1
View file →
| @@ -1,13 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\EditorOne\Classes; |
| 4 | 4 | |
| 5 | -use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_Interface; | |
| 6 | -use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_Third_Level_Interface; | |
| 7 | -use Elementor\Core\Admin\EditorOneMenu\Interfaces\Menu_Item_With_Custom_Url_Interface; | |
| 8 | 5 | use Elementor\Plugin; |
| 9 | -use Elementor\Utils; | |
| 6 | +use Elementor\Modules\EditorOne\Classes\Menu\Menu_Item_Interface; | |
| 7 | +use Elementor\Modules\EditorOne\Classes\Menu\Menu_Item_Third_Level_Interface; | |
| 10 | 8 | |
| 11 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | 10 | exit; |
| 13 | 11 | } |
| @@ -12,18 +10,16 @@ | ||
| 12 | 10 | exit; |
| 13 | 11 | } |
| 14 | 12 | |
| 15 | 13 | class Menu_Data_Provider { |
| 16 | - public const THIRD_LEVEL_EDITOR_FLYOUT = 'editor_flyout'; | |
| 17 | - public const THIRD_LEVEL_FLYOUT_MENU = 'flyout_menu'; | |
| 18 | 14 | |
| 19 | 15 | private static ?Menu_Data_Provider $instance = null; |
| 16 | + | |
| 20 | 17 | private array $level3_items = []; |
| 21 | 18 | private array $level4_items = []; |
| 22 | 19 | private ?string $theme_builder_url = null; |
| 23 | - private ?array $cached_level3_sidebar_data = null; | |
| 24 | - private ?array $cached_level4_sidebar_data = null; | |
| 25 | - private ?array $cached_flyout_menu_data = null; | |
| 20 | + private ?array $cached_editor_flyout_data = null; | |
| 21 | + private ?array $cached_level4_flyout_data = null; | |
| 26 | 22 | private Slug_Normalizer $slug_normalizer; |
| 27 | 23 | |
| 28 | 24 | public static function instance(): self { |
| 29 | 25 | if ( null === self::$instance ) { |
| @@ -41,25 +37,13 @@ | ||
| 41 | 37 | return $this->slug_normalizer; |
| 42 | 38 | } |
| 43 | 39 | |
| 44 | 40 | public function register_menu( Menu_Item_Interface $item ): void { |
| 45 | - if ( ! ( $item instanceof Menu_Item_Third_Level_Interface ) ) { | |
| 41 | + if ( $item instanceof Menu_Item_Third_Level_Interface ) { | |
| 42 | + $this->register_level3_item( $item ); | |
| 43 | + } else { | |
| 46 | 44 | $this->register_level4_item( $item ); |
| 47 | - return; | |
| 48 | 45 | } |
| 49 | - | |
| 50 | - $group_id = $item->get_group_id(); | |
| 51 | - $collapsible_groups = [ | |
| 52 | - Menu_Config::TEMPLATES_GROUP_ID, | |
| 53 | - Menu_Config::CUSTOM_ELEMENTS_GROUP_ID, | |
| 54 | - Menu_Config::SYSTEM_GROUP_ID, | |
| 55 | - ]; | |
| 56 | - | |
| 57 | - if ( in_array( $group_id, $collapsible_groups, true ) && ! $item->has_children() ) { | |
| 58 | - $this->register_level4_item( $item ); | |
| 59 | - } else { | |
| 60 | - $this->register_level3_item( $item ); | |
| 61 | - } | |
| 62 | 46 | } |
| 63 | 47 | |
| 64 | 48 | public function register_level3_item( Menu_Item_Third_Level_Interface $item ): void { |
| 65 | 49 | $group_id = $item->get_group_id(); |
| @@ -105,29 +89,28 @@ | ||
| 105 | 89 | |
| 106 | 90 | return false; |
| 107 | 91 | } |
| 108 | 92 | |
| 109 | - public function get_third_level_data( string $variant ): array { | |
| 110 | - if ( self::THIRD_LEVEL_EDITOR_FLYOUT === $variant ) { | |
| 111 | - return $this->get_third_level_data_from_cache( | |
| 112 | - $this->cached_level3_sidebar_data, | |
| 113 | - [ $this, 'build_level3_flyout_items' ] | |
| 114 | - ); | |
| 93 | + public function get_editor_flyout_data(): array { | |
| 94 | + if ( null !== $this->cached_editor_flyout_data ) { | |
| 95 | + return $this->cached_editor_flyout_data; | |
| 115 | 96 | } |
| 116 | 97 | |
| 117 | - if ( self::THIRD_LEVEL_FLYOUT_MENU === $variant ) { | |
| 118 | - return $this->get_third_level_data_from_cache( | |
| 119 | - $this->cached_flyout_menu_data, | |
| 120 | - [ $this, 'build_flyout_items_with_expanded_third_party' ] | |
| 121 | - ); | |
| 122 | - } | |
| 98 | + $items = $this->build_level3_flyout_items(); | |
| 123 | 99 | |
| 124 | - return []; | |
| 100 | + $this->sort_items_by_priority( $items ); | |
| 101 | + | |
| 102 | + $this->cached_editor_flyout_data = [ | |
| 103 | + 'parent_slug' => Menu_Config::EDITOR_MENU_SLUG, | |
| 104 | + 'items' => $items, | |
| 105 | + ]; | |
| 106 | + | |
| 107 | + return $this->cached_editor_flyout_data; | |
| 125 | 108 | } |
| 126 | 109 | |
| 127 | 110 | public function get_level4_flyout_data(): array { |
| 128 | - if ( null !== $this->cached_level4_sidebar_data ) { | |
| 129 | - return $this->cached_level4_sidebar_data; | |
| 111 | + if ( null !== $this->cached_level4_flyout_data ) { | |
| 112 | + return $this->cached_level4_flyout_data; | |
| 130 | 113 | } |
| 131 | 114 | |
| 132 | 115 | $groups = $this->build_level4_flyout_groups(); |
| 133 | 116 | |
| @@ -136,67 +119,24 @@ | ||
| 136 | 119 | $this->sort_items_by_priority( $groups[ $group_id ]['items'] ); |
| 137 | 120 | } |
| 138 | 121 | } |
| 139 | 122 | |
| 140 | - $this->cached_level4_sidebar_data = $groups; | |
| 123 | + $this->cached_level4_flyout_data = $groups; | |
| 141 | 124 | |
| 142 | - return $this->cached_level4_sidebar_data; | |
| 125 | + return $this->cached_level4_flyout_data; | |
| 143 | 126 | } |
| 144 | 127 | |
| 145 | - private function get_third_level_data_from_cache( ?array &$cache, callable $items_builder ): array { | |
| 146 | - if ( null !== $cache ) { | |
| 147 | - return $cache; | |
| 148 | - } | |
| 149 | - | |
| 150 | - $items = $items_builder(); | |
| 151 | - | |
| 152 | - $this->sort_items_by_priority( $items ); | |
| 153 | - | |
| 154 | - $cache = [ | |
| 155 | - 'parent_slug' => Menu_Config::EDITOR_MENU_SLUG, | |
| 156 | - 'items' => $items, | |
| 157 | - ]; | |
| 158 | - | |
| 159 | - return $cache; | |
| 160 | - } | |
| 161 | - | |
| 162 | 128 | public function get_theme_builder_url(): string { |
| 163 | 129 | if ( null === $this->theme_builder_url ) { |
| 164 | 130 | $pro_url = Plugin::$instance->app ? Plugin::$instance->app->get_settings( 'menu_url' ) : null; |
| 165 | - $return_to = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ); | |
| 131 | + $default_url = $pro_url ? $pro_url : admin_url( 'admin.php?page=elementor-app#site-editor/promotion' ); | |
| 166 | 132 | |
| 167 | - if ( $pro_url ) { | |
| 168 | - if ( false !== strpos( $pro_url, '#' ) ) { | |
| 169 | - $url = $this->add_return_to_url( $pro_url, $return_to ); | |
| 170 | - } else { | |
| 171 | - $url = $pro_url; | |
| 172 | - } | |
| 173 | - } else { | |
| 174 | - $url = $this->add_return_to_url( | |
| 175 | - admin_url( 'admin.php?page=elementor-app' ) . '#/site-editor/promotion', | |
| 176 | - $return_to | |
| 177 | - ); | |
| 178 | - } | |
| 179 | - | |
| 180 | - $this->theme_builder_url = apply_filters( 'elementor/editor-one/menu/theme_builder_url', $url ); | |
| 133 | + $this->theme_builder_url = apply_filters( 'elementor/editor-one/menu/theme_builder_url', $default_url ); | |
| 181 | 134 | } |
| 182 | 135 | |
| 183 | 136 | return $this->theme_builder_url; |
| 184 | 137 | } |
| 185 | 138 | |
| 186 | - private function add_return_to_url( string $url, string $return_to ): string { | |
| 187 | - $hash_position = strpos( $url, '#' ); | |
| 188 | - | |
| 189 | - if ( false === $hash_position ) { | |
| 190 | - return add_query_arg( [ 'return_to' => $return_to ], $url ); | |
| 191 | - } | |
| 192 | - | |
| 193 | - $base_url = substr( $url, 0, $hash_position ); | |
| 194 | - $hash_fragment = substr( $url, $hash_position ); | |
| 195 | - | |
| 196 | - return add_query_arg( [ 'return_to' => $return_to ], $base_url ) . $hash_fragment; | |
| 197 | - } | |
| 198 | - | |
| 199 | 139 | public function get_all_sidebar_page_slugs(): array { |
| 200 | 140 | $base_slugs = [ |
| 201 | 141 | Menu_Config::ELEMENTOR_MENU_SLUG, |
| 202 | 142 | Menu_Config::EDITOR_MENU_SLUG, |
| @@ -216,12 +156,8 @@ | ||
| 216 | 156 | } |
| 217 | 157 | |
| 218 | 158 | $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?? ''; |
| 219 | 159 | |
| 220 | - if ( Menu_Config::ELEMENTOR_HOME_MENU_SLUG === $page ) { | |
| 221 | - return false; | |
| 222 | - } | |
| 223 | - | |
| 224 | 160 | if ( in_array( $page, $this->get_all_sidebar_page_slugs(), true ) ) { |
| 225 | 161 | return true; |
| 226 | 162 | } |
| 227 | 163 | |
| @@ -229,28 +165,8 @@ | ||
| 229 | 165 | |
| 230 | 166 | return $this->is_elementor_post_type( $post_type ); |
| 231 | 167 | } |
| 232 | 168 | |
| 233 | - public function is_editor_one_post_edit_screen(): bool { | |
| 234 | - $screen = get_current_screen(); | |
| 235 | - | |
| 236 | - if ( ! $screen || empty( $screen->post_type ) ) { | |
| 237 | - return false; | |
| 238 | - } | |
| 239 | - | |
| 240 | - if ( 'post' !== $screen->base ) { | |
| 241 | - return false; | |
| 242 | - } | |
| 243 | - | |
| 244 | - $post_types = apply_filters( 'elementor/editor-one/admin-edit-post-types', [] ); | |
| 245 | - | |
| 246 | - return in_array( $screen->post_type, $post_types, true ); | |
| 247 | - } | |
| 248 | - | |
| 249 | - public function is_editor_one_admin_page(): bool { | |
| 250 | - return $this->is_elementor_editor_page() || $this->is_editor_one_post_edit_screen(); | |
| 251 | - } | |
| 252 | - | |
| 253 | 169 | private function is_elementor_post_type( string $post_type ): bool { |
| 254 | 170 | if ( empty( $post_type ) ) { |
| 255 | 171 | return false; |
| 256 | 172 | } |
| @@ -282,44 +198,16 @@ | ||
| 282 | 198 | if ( 0 === strpos( $slug, $prefix ) ) { |
| 283 | 199 | return true; |
| 284 | 200 | } |
| 285 | 201 | } |
| 286 | - | |
| 287 | 202 | return false; |
| 288 | 203 | } ) ); |
| 289 | 204 | } |
| 290 | 205 | |
| 291 | 206 | private function build_level3_flyout_items(): array { |
| 292 | - return $this->build_flyout_items( false ); | |
| 293 | - } | |
| 294 | - | |
| 295 | - private function build_flyout_items_with_expanded_third_party(): array { | |
| 296 | - $items = $this->build_flyout_items( true ); | |
| 297 | - | |
| 298 | - if ( ! Utils::has_pro() ) { | |
| 299 | - $items[] = $this->build_theme_builder_flyout_item(); | |
| 300 | - } | |
| 301 | - | |
| 302 | - return $items; | |
| 303 | - } | |
| 304 | - | |
| 305 | - private function build_theme_builder_flyout_item(): array { | |
| 306 | - return [ | |
| 307 | - 'slug' => 'elementor-theme-builder', | |
| 308 | - 'label' => esc_html__( 'Theme Builder', 'elementor' ), | |
| 309 | - 'url' => $this->get_theme_builder_url(), | |
| 310 | - 'icon' => 'theme-builder', | |
| 311 | - 'group_id' => '', | |
| 312 | - 'priority' => 50, | |
| 313 | - 'has_divider_before' => false, | |
| 314 | - ]; | |
| 315 | - } | |
| 316 | - | |
| 317 | - private function build_flyout_items( bool $expand_third_party ): array { | |
| 318 | 207 | $items = []; |
| 319 | 208 | $existing_slugs = []; |
| 320 | 209 | $excluded_slugs = Menu_Config::get_excluded_level3_slugs(); |
| 321 | - $excluded_level4_slugs = $expand_third_party ? Menu_Config::get_excluded_level4_slugs() : []; | |
| 322 | 210 | |
| 323 | 211 | foreach ( $this->level3_items as $group_items ) { |
| 324 | 212 | foreach ( $group_items as $item_slug => $item ) { |
| 325 | 213 | if ( ! $this->should_include_flyout_item( $item, $item_slug, $existing_slugs, $excluded_slugs ) ) { |
| @@ -325,33 +213,8 @@ | ||
| 325 | 213 | if ( ! $this->should_include_flyout_item( $item, $item_slug, $existing_slugs, $excluded_slugs ) ) { |
| 326 | 214 | continue; |
| 327 | 215 | } |
| 328 | 216 | |
| 329 | - if ( $expand_third_party && $this->is_third_party_parent_with_children( $item ) ) { | |
| 330 | - $children = $this->level4_items[ Menu_Config::THIRD_PARTY_GROUP_ID ] ?? []; | |
| 331 | - $is_first_child = true; | |
| 332 | - | |
| 333 | - foreach ( $children as $child_slug => $child ) { | |
| 334 | - if ( ! $this->is_item_accessible( $child ) ) { | |
| 335 | - continue; | |
| 336 | - } | |
| 337 | - | |
| 338 | - if ( $this->is_slug_excluded( $child_slug, $excluded_level4_slugs, true ) ) { | |
| 339 | - continue; | |
| 340 | - } | |
| 341 | - | |
| 342 | - if ( in_array( $child_slug, $existing_slugs, true ) ) { | |
| 343 | - continue; | |
| 344 | - } | |
| 345 | - | |
| 346 | - $child_data = $this->create_expanded_child_item_data( $child, $child_slug, $is_first_child ); | |
| 347 | - $items[] = $child_data; | |
| 348 | - $existing_slugs[] = $child_slug; | |
| 349 | - $is_first_child = false; | |
| 350 | - } | |
| 351 | - continue; | |
| 352 | - } | |
| 353 | - | |
| 354 | 217 | $items[] = $this->create_flyout_item_data( $item, $item_slug ); |
| 355 | 218 | $existing_slugs[] = $item_slug; |
| 356 | 219 | } |
| 357 | 220 | } |
| @@ -358,35 +221,8 @@ | ||
| 358 | 221 | |
| 359 | 222 | return $items; |
| 360 | 223 | } |
| 361 | 224 | |
| 362 | - private function is_third_party_parent_with_children( Menu_Item_Interface $item ): bool { | |
| 363 | - if ( Menu_Config::THIRD_PARTY_GROUP_ID !== $item->get_group_id() ) { | |
| 364 | - return false; | |
| 365 | - } | |
| 366 | - | |
| 367 | - if ( ! $item->has_children() ) { | |
| 368 | - return false; | |
| 369 | - } | |
| 370 | - | |
| 371 | - $children = $this->level4_items[ Menu_Config::THIRD_PARTY_GROUP_ID ] ?? []; | |
| 372 | - | |
| 373 | - return ! empty( $children ); | |
| 374 | - } | |
| 375 | - | |
| 376 | - private function create_expanded_child_item_data( Menu_Item_Interface $item, string $item_slug, bool $is_first ): array { | |
| 377 | - $url = $this->resolve_item_url( $item, $item_slug ); | |
| 378 | - | |
| 379 | - return [ | |
| 380 | - 'slug' => $item_slug, | |
| 381 | - 'label' => $this->title_case( $item->get_label() ), | |
| 382 | - 'url' => $url, | |
| 383 | - 'group_id' => '', | |
| 384 | - 'priority' => $this->get_item_priority( $item ), | |
| 385 | - 'has_divider_before' => $is_first, | |
| 386 | - ]; | |
| 387 | - } | |
| 388 | - | |
| 389 | 225 | private function should_include_flyout_item( Menu_Item_Interface $item, string $item_slug, array $existing_slugs, array $excluded_slugs ): bool { |
| 390 | 226 | if ( ! $this->is_item_accessible( $item ) ) { |
| 391 | 227 | return false; |
| 392 | 228 | } |
| @@ -394,9 +230,9 @@ | ||
| 394 | 230 | if ( in_array( $item_slug, $existing_slugs, true ) ) { |
| 395 | 231 | return false; |
| 396 | 232 | } |
| 397 | 233 | |
| 398 | - if ( $this->is_slug_excluded( $item_slug, $excluded_slugs ) ) { | |
| 234 | + if ( in_array( $item_slug, $excluded_slugs, true ) ) { | |
| 399 | 235 | return false; |
| 400 | 236 | } |
| 401 | 237 | |
| 402 | 238 | if ( empty( trim( wp_strip_all_tags( $item->get_label() ) ) ) ) { |
| @@ -408,23 +244,21 @@ | ||
| 408 | 244 | |
| 409 | 245 | private function create_flyout_item_data( Menu_Item_Interface $item, string $item_slug ): array { |
| 410 | 246 | $has_children = $item->has_children(); |
| 411 | 247 | $group_id = $has_children ? $item->get_group_id() : ''; |
| 412 | - $is_third_party_parent = Menu_Config::THIRD_PARTY_GROUP_ID === $item->get_group_id(); | |
| 413 | 248 | |
| 414 | 249 | return [ |
| 415 | 250 | 'slug' => $item_slug, |
| 416 | - 'label' => $this->title_case( $item->get_label() ), | |
| 251 | + 'label' => $item->get_label(), | |
| 417 | 252 | 'url' => $this->resolve_flyout_item_url( $item, $item_slug ), |
| 418 | 253 | 'icon' => $item->get_icon(), |
| 419 | 254 | 'group_id' => $group_id, |
| 420 | - 'priority' => $this->get_item_priority( $item ), | |
| 421 | - 'has_divider_before' => $is_third_party_parent, | |
| 255 | + 'priority' => $item->get_position() ?? 100, | |
| 422 | 256 | ]; |
| 423 | 257 | } |
| 424 | 258 | |
| 425 | 259 | private function resolve_flyout_item_url( Menu_Item_Interface $item, string $item_slug ): string { |
| 426 | - $url = $this->resolve_item_url( $item, $item_slug ); | |
| 260 | + $url = $this->get_item_url( $item_slug, $item->get_parent_slug() ); | |
| 427 | 261 | |
| 428 | 262 | if ( ! $item->has_children() ) { |
| 429 | 263 | return $url; |
| 430 | 264 | } |
| @@ -448,10 +282,10 @@ | ||
| 448 | 282 | continue; |
| 449 | 283 | } |
| 450 | 284 | |
| 451 | 285 | $children_data[] = [ |
| 452 | - 'url' => $this->resolve_item_url( $child_item, $child_slug ), | |
| 453 | - 'priority' => $this->get_item_priority( $child_item ), | |
| 286 | + 'url' => $this->get_item_url( $child_slug, $child_item->get_parent_slug() ), | |
| 287 | + 'priority' => $child_item->get_position() ?? 100, | |
| 454 | 288 | ]; |
| 455 | 289 | } |
| 456 | 290 | |
| 457 | 291 | if ( empty( $children_data ) ) { |
| @@ -475,9 +309,9 @@ | ||
| 475 | 309 | if ( ! $this->is_item_accessible( $item ) ) { |
| 476 | 310 | continue; |
| 477 | 311 | } |
| 478 | 312 | |
| 479 | - if ( $this->is_slug_excluded( $item_slug, $excluded_slugs, true ) ) { | |
| 313 | + if ( $this->slug_normalizer->is_excluded( $item_slug, $excluded_slugs ) ) { | |
| 480 | 314 | continue; |
| 481 | 315 | } |
| 482 | 316 | |
| 483 | 317 | $label = $item->get_label(); |
| @@ -486,15 +320,13 @@ | ||
| 486 | 320 | if ( in_array( $label_lower, $existing_labels, true ) ) { |
| 487 | 321 | continue; |
| 488 | 322 | } |
| 489 | 323 | |
| 490 | - $url = $this->resolve_item_url( $item, $item_slug ); | |
| 491 | - | |
| 492 | 324 | $groups[ $group_id ]['items'][] = [ |
| 493 | 325 | 'slug' => $item_slug, |
| 494 | - 'label' => $this->title_case( $item->get_label() ), | |
| 495 | - 'url' => $url, | |
| 496 | - 'priority' => $this->get_item_priority( $item ), | |
| 326 | + 'label' => $label, | |
| 327 | + 'url' => $this->get_item_url( $item_slug, $item->get_parent_slug() ), | |
| 328 | + 'priority' => $item->get_position() ?? 100, | |
| 497 | 329 | ]; |
| 498 | 330 | |
| 499 | 331 | $existing_labels[] = $label_lower; |
| 500 | 332 | } |
| @@ -502,9 +334,9 @@ | ||
| 502 | 334 | |
| 503 | 335 | return $groups; |
| 504 | 336 | } |
| 505 | 337 | |
| 506 | - public function is_item_accessible( Menu_Item_Interface $item ): bool { | |
| 338 | + private function is_item_accessible( Menu_Item_Interface $item ): bool { | |
| 507 | 339 | return $item->is_visible() && current_user_can( $item->get_capability() ); |
| 508 | 340 | } |
| 509 | 341 | |
| 510 | 342 | private function get_item_url( string $item_slug, ?string $parent_slug = null ): string { |
| @@ -526,28 +358,8 @@ | ||
| 526 | 358 | |
| 527 | 359 | return admin_url( 'admin.php?page=' . $item_slug ); |
| 528 | 360 | } |
| 529 | 361 | |
| 530 | - private function resolve_item_url( Menu_Item_Interface $item, string $item_slug ): string { | |
| 531 | - if ( $item instanceof Menu_Item_With_Custom_Url_Interface ) { | |
| 532 | - return $item->get_menu_url(); | |
| 533 | - } | |
| 534 | - | |
| 535 | - return $this->get_item_url( $item_slug, $item->get_parent_slug() ); | |
| 536 | - } | |
| 537 | - | |
| 538 | - private function get_item_priority( Menu_Item_Interface $item ): int { | |
| 539 | - return $item->get_position() ?? 100; | |
| 540 | - } | |
| 541 | - | |
| 542 | - private function is_slug_excluded( string $item_slug, array $excluded_slugs, bool $use_normalizer = false ): bool { | |
| 543 | - if ( $use_normalizer ) { | |
| 544 | - return $this->slug_normalizer->is_excluded( $item_slug, $excluded_slugs ); | |
| 545 | - } | |
| 546 | - | |
| 547 | - return in_array( $item_slug, $excluded_slugs, true ); | |
| 548 | - } | |
| 549 | - | |
| 550 | 362 | private function sort_items_by_priority( array &$items ): void { |
| 551 | 363 | usort( $items, function ( array $a, array $b ): int { |
| 552 | 364 | return ( $a['priority'] ?? 100 ) <=> ( $b['priority'] ?? 100 ); |
| 553 | 365 | } ); |
| @@ -552,42 +364,9 @@ | ||
| 552 | 364 | return ( $a['priority'] ?? 100 ) <=> ( $b['priority'] ?? 100 ); |
| 553 | 365 | } ); |
| 554 | 366 | } |
| 555 | 367 | |
| 556 | - private function title_case( string $text ): string { | |
| 557 | - if ( function_exists( 'mb_convert_case' ) ) { | |
| 558 | - return mb_convert_case( $text, MB_CASE_TITLE, 'UTF-8' ); | |
| 559 | - } | |
| 560 | - | |
| 561 | - return ucwords( strtolower( $text ) ); | |
| 562 | - } | |
| 563 | - | |
| 564 | 368 | private function invalidate_cache(): void { |
| 565 | - $this->cached_level3_sidebar_data = null; | |
| 566 | - $this->cached_level4_sidebar_data = null; | |
| 567 | - $this->cached_flyout_menu_data = null; | |
| 568 | - } | |
| 569 | - | |
| 570 | - public static function get_current_user_capabilities(): array { | |
| 571 | - $user = wp_get_current_user(); | |
| 572 | - | |
| 573 | - if ( ! $user || ! $user->exists() ) { | |
| 574 | - return [ | |
| 575 | - 'user' => null, | |
| 576 | - 'has_edit_posts' => false, | |
| 577 | - 'has_manage_options' => false, | |
| 578 | - 'is_edit_posts_user' => false, | |
| 579 | - ]; | |
| 580 | - } | |
| 581 | - | |
| 582 | - $has_edit_posts = isset( $user->allcaps[ Menu_Config::CAPABILITY_EDIT_POSTS ] ) && $user->allcaps[ Menu_Config::CAPABILITY_EDIT_POSTS ]; | |
| 583 | - $has_manage_options = isset( $user->allcaps[ Menu_Config::CAPABILITY_MANAGE_OPTIONS ] ) && $user->allcaps[ Menu_Config::CAPABILITY_MANAGE_OPTIONS ]; | |
| 584 | - $is_edit_posts_user = $has_edit_posts && ! $has_manage_options; | |
| 585 | - | |
| 586 | - return [ | |
| 587 | - 'user' => $user, | |
| 588 | - 'has_edit_posts' => $has_edit_posts, | |
| 589 | - 'has_manage_options' => $has_manage_options, | |
| 590 | - 'is_edit_posts_user' => $is_edit_posts_user, | |
| 591 | - ]; | |
| 369 | + $this->cached_editor_flyout_data = null; | |
| 370 | + $this->cached_level4_flyout_data = null; | |
| 592 | 371 | } |
| 593 | 372 | } |