Skip to content

Commit 0cda9e4

Browse files
authored
Check if script is enqueued, add shortcut
1 parent e35f13b commit 0cda9e4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/wp-includes/admin-bar.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,14 +1215,20 @@ function wp_admin_bar_search_menu( $wp_admin_bar ) {
12151215
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
12161216
*/
12171217
function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void {
1218-
if ( ! is_admin() || ! current_user_can( 'edit_posts' ) ) {
1218+
if ( ! is_admin() || ! wp_script_is( 'wp-core-commands', 'enqueued' ) ) {
12191219
return;
12201220
}
12211221

1222-
$title = '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' .
1222+
$is_apple_os = (bool) preg_match( '/Macintosh|Mac OS X|Mac_PowerPC/i', $_SERVER['HTTP_USER_AGENT'] ?? '' );
1223+
$shortcut_label = $is_apple_os
1224+
? _x( '⌘K', 'keyboard shortcut to open the command palette' )
1225+
: _x( 'Ctrl+K', 'keyboard shortcut to open the command palette' );
1226+
$title = sprintf(
1227+
'<span class="ab-icon" aria-hidden="true"></span><span class="ab-label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span>',
1228+
$shortcut_label,
12231229
/* translators: Hidden accessibility text. */
1224-
__( 'Open command palette' ) .
1225-
'</span>';
1230+
__( 'Open command palette' ),
1231+
);
12261232

12271233
$wp_admin_bar->add_node(
12281234
array(

0 commit comments

Comments
 (0)