← All changes
|
jetpack_vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php
+27
-25
16.3-a.5
→
16.3-beta
View file →
| @@ -17,9 +17,9 @@ | ||
| 17 | 17 | * If the Jetpack top level was not previously registered by other plugin, it will be registered here. |
| 18 | 18 | */ |
| 19 | 19 | class Admin_Menu { |
| 20 | 20 | |
| 21 | - const PACKAGE_VERSION = '0.14.1'; | |
| 21 | + const PACKAGE_VERSION = '0.14.3'; | |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Slug used for the upgrade menu item and redirect URL. |
| 25 | 25 | * |
| @@ -97,13 +97,11 @@ | ||
| 97 | 97 | self::POSITION_LAST, |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | - * Handle for the shared, token-only WPDS design-tokens stylesheet. | |
| 101 | + * Handle for the bundled WPDS design-tokens stylesheet. | |
| 102 | 102 | * |
| 103 | - * Registered once and enqueued on every Jetpack admin page so that | |
| 104 | - * `var(--wpds-*)` values resolve at runtime instead of falling back to | |
| 105 | - * their hand-written hex defaults. | |
| 103 | + * Fallback when Core/Gutenberg has not registered the `wp-theme` style. | |
| 106 | 104 | * |
| 107 | 105 | * @var string |
| 108 | 106 | */ |
| 109 | 107 | const DESIGN_TOKENS_HANDLE = 'jetpack-admin-ui-design-tokens'; |
| @@ -473,21 +471,24 @@ | ||
| 473 | 471 | self::$menu_items[] = compact( 'page_title', 'menu_title', 'capability', 'menu_slug', 'function', 'position', 'args' ); |
| 474 | 472 | |
| 475 | 473 | /** |
| 476 | 474 | * Let's return the page hook so consumers can use. |
| 477 | - * We know all pages will be under Jetpack top level menu page, so we can hardcode the first part of the string. | |
| 475 | + * Pages normally sit under the Jetpack top level menu page, so we can hardcode the first part of the string. | |
| 478 | 476 | * Using get_plugin_page_hookname here won't work because the top level page is not registered yet. |
| 479 | 477 | */ |
| 480 | 478 | $hook = 'jetpack_page_' . $menu_slug; |
| 481 | 479 | |
| 482 | - // Track the page hook so the design-tokens stylesheet can be scoped to it. | |
| 483 | - self::$page_hooks[] = $hook; | |
| 480 | + // Core names the page admin_page_<slug> instead when the user has no Jetpack top-level menu. | |
| 481 | + foreach ( array( $hook, 'admin_page_' . $menu_slug ) as $page_hook ) { | |
| 482 | + // Track the page hook so the design-tokens stylesheet can be scoped to it. | |
| 483 | + self::$page_hooks[] = $page_hook; | |
| 484 | 484 | |
| 485 | - // Hide WordPress core admin notices on this Jetpack page. The load-<hook> | |
| 486 | - // action only fires when the matching screen is being rendered, so this | |
| 487 | - // stays scoped to Jetpack pages and reaches every page registered here. | |
| 488 | - add_action( 'load-' . $hook, array( __CLASS__, 'hide_core_admin_notices' ) ); | |
| 489 | - add_action( 'load-' . $hook . '-network', array( __CLASS__, 'hide_core_admin_notices' ) ); | |
| 485 | + // Hide WordPress core admin notices on this Jetpack page. The load-<hook> | |
| 486 | + // action only fires when the matching screen is being rendered, so this | |
| 487 | + // stays scoped to Jetpack pages and reaches every page registered here. | |
| 488 | + add_action( 'load-' . $page_hook, array( __CLASS__, 'hide_core_admin_notices' ) ); | |
| 489 | + add_action( 'load-' . $page_hook . '-network', array( __CLASS__, 'hide_core_admin_notices' ) ); | |
| 490 | + } | |
| 490 | 491 | |
| 491 | 492 | return $hook; |
| 492 | 493 | } |
| 493 | 494 | |
| @@ -921,31 +922,32 @@ | ||
| 921 | 922 | self::enqueue_upgrade_menu_tracks_script( $asset ); |
| 922 | 923 | } |
| 923 | 924 | |
| 924 | 925 | /** |
| 925 | - * Enqueues the shared, token-only WPDS design-tokens stylesheet. | |
| 926 | + * Enqueues WPDS design tokens so `var(--wpds-*)` values resolve at runtime. | |
| 926 | 927 | * |
| 927 | - * Single entry point for any consumer that needs WPDS `var(--wpds-*)` values | |
| 928 | - * to resolve at runtime on a Jetpack admin page. Registers the handle on | |
| 929 | - * first use (idempotent) and enqueues it; the caller is responsible for | |
| 930 | - * scoping the call to the right page(s). Since admin-ui is a dependency of | |
| 931 | - * the Jetpack plugin and the modernized packages, both the plugin's | |
| 932 | - * legacy/wrap_ui gate and this package's own dashboards call through here, | |
| 933 | - * so the handle has a single owner and there is no duplicated enqueue logic. | |
| 928 | + * Prefer Core/Gutenberg's `wp-theme` style when registered; otherwise ship | |
| 929 | + * the bundled copy. The caller scopes the call to the right page(s). | |
| 934 | 930 | * |
| 935 | 931 | * @return void |
| 936 | 932 | */ |
| 937 | 933 | public static function enqueue_design_tokens() { |
| 934 | + // Registered since WP 7.1 (and by Gutenberg): | |
| 935 | + // https://make.wordpress.org/core/2026/07/31/design-system-theming-in-wordpress-7-1/ | |
| 936 | + if ( wp_style_is( 'wp-theme', 'registered' ) ) { | |
| 937 | + wp_enqueue_style( 'wp-theme' ); | |
| 938 | + return; | |
| 939 | + } | |
| 940 | + | |
| 941 | + // @todo Remove this, the called function, and the webpack entrypoint it registers when WP 7.1 is the minimum version. | |
| 938 | 942 | self::register_design_tokens_style(); |
| 939 | 943 | wp_enqueue_style( self::DESIGN_TOKENS_HANDLE ); |
| 940 | 944 | } |
| 941 | 945 | |
| 942 | 946 | /** |
| 943 | - * Registers the shared, token-only WPDS design-tokens stylesheet. | |
| 947 | + * Registers the bundled, token-only WPDS design-tokens stylesheet. | |
| 944 | 948 | * |
| 945 | - * The stylesheet only defines `:root{--wpds-*}` custom properties (no | |
| 946 | - * component or class styles), giving every Jetpack admin page a single | |
| 947 | - * runtime source for design tokens. It is safe to call repeatedly: | |
| 949 | + * Used only when `wp-theme` is not registered. Safe to call repeatedly: | |
| 948 | 950 | * wp_register_style() is a no-op once the handle is registered. |
| 949 | 951 | * |
| 950 | 952 | * @return void |
| 951 | 953 | */ |