55 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
66 */
77function gutenberg_admin_bar_command_palette_menu ( WP_Admin_Bar $ wp_admin_bar ): void {
8- if ( ! is_admin () ) {
8+ if ( ! is_admin () || ! wp_script_is ( ' wp-core-commands ' , ' enqueued ' ) ) {
99 return ;
1010 }
1111
1212 $ is_apple_os = (bool ) preg_match ( '/Macintosh|Mac OS X|Mac_PowerPC/i ' , $ _SERVER ['HTTP_USER_AGENT ' ] ?? '' );
1313 $ shortcut_label = $ is_apple_os
14- ? _x ( '⌘K ' , 'keyboard shortcut to open the command palette ' , ' gutenberg ' )
15- : _x ( 'Ctrl+K ' , 'keyboard shortcut to open the command palette ' , ' gutenberg ' );
14+ ? _x ( '⌘K ' , 'keyboard shortcut to open the command palette ' )
15+ : _x ( 'Ctrl+K ' , 'keyboard shortcut to open the command palette ' );
1616 $ title = sprintf (
17- '<span class="ab-label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span> ' ,
17+ '<span class="ab-icon" aria-hidden="true"></span><span class="ab- label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span> ' ,
1818 $ shortcut_label ,
1919 /* translators: Hidden accessibility text. */
20- __ ( 'Open command palette ' , ' gutenberg ' ),
20+ __ ( 'Open command palette ' ),
2121 );
2222 $ wp_admin_bar ->add_node (
2323 array (
@@ -35,3 +35,47 @@ function gutenberg_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ):
3535 remove_action ( 'admin_bar_menu ' , 'wp_admin_bar_command_palette_menu ' , 55 );
3636}
3737add_action ( 'admin_bar_menu ' , 'gutenberg_admin_bar_command_palette_menu ' , 55 );
38+
39+ function gutenberg_add_admin_bar_styles () {
40+ if ( ! is_admin_bar_showing () ) {
41+ return ;
42+ }
43+ $ css = <<<CSS
44+ #wpadminbar #wp-admin-bar-command-palette .ab-icon {
45+ display: none; /* Icon displayed only on mobile */
46+ }
47+ #wpadminbar #wp-admin-bar-command-palette .ab-icon:before {
48+ content: "\\f179";
49+ content: "\\f179" / '';
50+ }
51+ #wpadminbar #wp-admin-bar-command-palette kbd {
52+ background: transparent;
53+ }
54+ @media screen and (max-width: 782px) {
55+ #wpadminbar #wp-admin-bar-command-palette .ab-icon {
56+ display: block; /* Icon is only shown on mobile, while the keyboard shortcut is hidden */
57+ }
58+ #wpadminbar #wp-admin-bar-command-palette .ab-icon:before {
59+ text-indent: 0;
60+ font: normal 32px/1 dashicons;
61+ width: 52px;
62+ text-align: center;
63+ -webkit-font-smoothing: antialiased;
64+ -moz-osx-font-smoothing: grayscale;
65+ display: block;
66+ font-size: 34px;
67+ height: 46px;
68+ line-height: 1.38235294;
69+ top: 0;
70+ }
71+ #wpadminbar li#wp-admin-bar-command-palette {
72+ display: block;
73+ }
74+ #wpadminbar #wp-admin-bar-command-palette {
75+ position: static;
76+ }
77+ }
78+ CSS ;
79+ wp_add_inline_style ( 'admin-bar ' , $ css );
80+ }
81+ add_action ( 'admin_bar_init ' , 'gutenberg_add_admin_bar_styles ' );
0 commit comments