From e613f79b9402b8a97cfff8363167fcf5239986f3 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Fri, 27 Feb 2026 00:29:44 +0900 Subject: [PATCH 1/3] Add command palette trigger button to admin bar --- src/wp-includes/admin-bar.php | 35 ++++++++++++++++++++++++++ src/wp-includes/class-wp-admin-bar.php | 3 +++ 2 files changed, 38 insertions(+) diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 9fc3c2b46b348..173d760aceb67 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -934,6 +934,41 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { } } +/** + * Adds the command palette trigger button. + * + * Displays a button in the admin bar that shows the keyboard shortcut + * for opening the command palette. + * + * @since 7.0.0 + * + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. + */ +function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void { + if ( ! is_admin() ) { + return; + } + + $is_apple_os = (bool) preg_match( '/Macintosh|Mac OS X|Mac_PowerPC/i', $_SERVER['HTTP_USER_AGENT'] ?? '' ); + $shortcut_label = $is_apple_os + ? _x( '⌘K', 'keyboard shortcut to open the command palette', 'gutenberg' ) + : _x( 'Ctrl+K', 'keyboard shortcut to open the command palette', 'gutenberg' ); + $title = sprintf( + '%s %s', + $shortcut_label, + /* translators: Hidden accessibility text. */ + __( 'Open command palette', 'gutenberg' ), + ); + $wp_admin_bar->add_node( + array( + 'id' => 'command-palette', + 'title' => $title, + 'href' => '#', + 'meta' => array( 'class' => 'hide-if-no-js' ), + ) + ); +} + /** * Adds "Add New" menu. * diff --git a/src/wp-includes/class-wp-admin-bar.php b/src/wp-includes/class-wp-admin-bar.php index dfebbb20e4c86..0c6ab15553bb2 100644 --- a/src/wp-includes/class-wp-admin-bar.php +++ b/src/wp-includes/class-wp-admin-bar.php @@ -661,6 +661,9 @@ public function add_menus() { add_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 ); add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 ); + // Command palette. + add_action( 'admin_bar_menu', 'wp_admin_bar_command_palette_menu', 55 ); + // Content-related. if ( ! is_network_admin() && ! is_user_admin() ) { add_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); From dbd527fa73a806042a6fbedf5a2bc8c4d75c7072 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Fri, 27 Feb 2026 16:33:22 +0900 Subject: [PATCH 2/3] Try inline server-side version --- src/wp-includes/admin-bar.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 173d760aceb67..d3add1e6dc8a9 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -951,20 +951,23 @@ function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void { $is_apple_os = (bool) preg_match( '/Macintosh|Mac OS X|Mac_PowerPC/i', $_SERVER['HTTP_USER_AGENT'] ?? '' ); $shortcut_label = $is_apple_os - ? _x( '⌘K', 'keyboard shortcut to open the command palette', 'gutenberg' ) - : _x( 'Ctrl+K', 'keyboard shortcut to open the command palette', 'gutenberg' ); + ? _x( '⌘K', 'keyboard shortcut to open the command palette' ) + : _x( 'Ctrl+K', 'keyboard shortcut to open the command palette' ); $title = sprintf( '%s %s', $shortcut_label, /* translators: Hidden accessibility text. */ - __( 'Open command palette', 'gutenberg' ), + __( 'Open command palette' ), ); $wp_admin_bar->add_node( array( 'id' => 'command-palette', 'title' => $title, 'href' => '#', - 'meta' => array( 'class' => 'hide-if-no-js' ), + 'meta' => array( + 'class' => 'hide-if-no-js', + 'onclick' => 'if ( window.wp && wp.data && wp.data.dispatch ) { var store = wp.data.dispatch( "core/commands" ); if ( store && typeof store.open === "function" ) { store.open(); } } return false;', + ), ) ); } From 1f988f886ad3e23be5506ef17dfc9b87c095572b Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Fri, 27 Feb 2026 16:45:18 +0900 Subject: [PATCH 3/3] Simplify onClick event process --- src/wp-includes/admin-bar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index d3add1e6dc8a9..b35d50a5daf3c 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -966,7 +966,7 @@ function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void { 'href' => '#', 'meta' => array( 'class' => 'hide-if-no-js', - 'onclick' => 'if ( window.wp && wp.data && wp.data.dispatch ) { var store = wp.data.dispatch( "core/commands" ); if ( store && typeof store.open === "function" ) { store.open(); } } return false;', + 'onclick' => 'wp.data.dispatch( "core/commands" ).open(); return false;', ), ) );