File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -934,6 +934,44 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) {
934934 }
935935}
936936
937+ /**
938+ * Adds the command palette trigger button.
939+ *
940+ * Displays a button in the admin bar that shows the keyboard shortcut
941+ * for opening the command palette.
942+ *
943+ * @since 7.0.0
944+ *
945+ * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
946+ */
947+ function wp_admin_bar_command_palette_menu ( WP_Admin_Bar $ wp_admin_bar ): void {
948+ if ( ! is_admin () ) {
949+ return ;
950+ }
951+
952+ $ is_apple_os = (bool ) preg_match ( '/Macintosh|Mac OS X|Mac_PowerPC/i ' , $ _SERVER ['HTTP_USER_AGENT ' ] ?? '' );
953+ $ shortcut_label = $ is_apple_os
954+ ? _x ( '⌘K ' , 'keyboard shortcut to open the command palette ' )
955+ : _x ( 'Ctrl+K ' , 'keyboard shortcut to open the command palette ' );
956+ $ title = sprintf (
957+ '<span class="ab-label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span> ' ,
958+ $ shortcut_label ,
959+ /* translators: Hidden accessibility text. */
960+ __ ( 'Open command palette ' ),
961+ );
962+ $ wp_admin_bar ->add_node (
963+ array (
964+ 'id ' => 'command-palette ' ,
965+ 'title ' => $ title ,
966+ 'href ' => '# ' ,
967+ 'meta ' => array (
968+ 'class ' => 'hide-if-no-js ' ,
969+ 'onclick ' => 'wp.data.dispatch( "core/commands" ).open(); return false; ' ,
970+ ),
971+ )
972+ );
973+ }
974+
937975/**
938976 * Adds "Add New" menu.
939977 *
Original file line number Diff line number Diff line change @@ -661,6 +661,9 @@ public function add_menus() {
661661 add_action ( 'admin_bar_menu ' , 'wp_admin_bar_customize_menu ' , 40 );
662662 add_action ( 'admin_bar_menu ' , 'wp_admin_bar_updates_menu ' , 50 );
663663
664+ // Command palette.
665+ add_action ( 'admin_bar_menu ' , 'wp_admin_bar_command_palette_menu ' , 55 );
666+
664667 // Content-related.
665668 if ( ! is_network_admin () && ! is_user_admin () ) {
666669 add_action ( 'admin_bar_menu ' , 'wp_admin_bar_comments_menu ' , 60 );
You can’t perform that action at this time.
0 commit comments