Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/wp-includes/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,43 @@ function wp_admin_bar_search_menu( $wp_admin_bar ) {
);
}

/**
* Adds a link to open 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() || ! wp_script_is( 'wp-core-commands', 'enqueued' ) ) {
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' )
: _x( 'Ctrl+K', 'keyboard shortcut to open the command palette' );
Comment thread
westonruter marked this conversation as resolved.
Outdated
$title = sprintf(
'<span class="ab-icon" aria-hidden="true"></span><span class="ab-label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span>',
$shortcut_label,
/* translators: Hidden accessibility text. */
__( 'Open command palette' ),
);

$wp_admin_bar->add_node(
array(
'parent' => 'top-secondary',
'id' => 'command-palette',
'title' => $title,
'href' => '#',
'meta' => array(
'class' => 'hide-if-no-js',
'onclick' => 'wp.data.dispatch( "core/commands" ).open(); return false;',
),
)
);
}

/**
* Adds a link to exit recovery mode when Recovery Mode is active.
*
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/class-wp-admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ public function add_menus() {
add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 9991 );
add_action( 'admin_bar_menu', 'wp_admin_bar_recovery_mode_menu', 9992 );
add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 9999 );
add_action( 'admin_bar_menu', 'wp_admin_bar_command_palette_menu', 9999 );
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is separate from the Search node in case someone wants to disable one and keep the other, but it is set at the same priority.


// Site-related.
add_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 );
Expand Down
34 changes: 30 additions & 4 deletions src/wp-includes/css/admin-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,24 @@ html:lang(he-il) .rtl #wpadminbar * {
display: none;
}

/**
* Command Palette
*/
#wpadminbar #wp-admin-bar-command-palette .ab-icon {
margin: 0;
}

#wpadminbar #wp-admin-bar-command-palette .ab-icon:before {
content: "\f179";
content: "\f179" / '';
top: 2px;
left: -2px;
}

#wpadminbar #wp-admin-bar-command-palette kbd {
background: transparent;
}

/**
* Customize support classes
*/
Expand Down Expand Up @@ -874,7 +892,8 @@ html:lang(he-il) .rtl #wpadminbar * {
#wpadminbar #wp-admin-bar-site-editor > .ab-item,
#wpadminbar #wp-admin-bar-customize > .ab-item,
#wpadminbar #wp-admin-bar-edit > .ab-item,
#wpadminbar #wp-admin-bar-my-account > .ab-item {
#wpadminbar #wp-admin-bar-my-account > .ab-item,
#wpadminbar #wp-admin-bar-command-palette > .ab-item {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
Expand All @@ -896,7 +915,8 @@ html:lang(he-il) .rtl #wpadminbar * {
#wpadminbar #wp-admin-bar-site-name > .ab-item:before,
#wpadminbar #wp-admin-bar-site-editor > .ab-item:before,
#wpadminbar #wp-admin-bar-customize > .ab-item:before,
#wpadminbar #wp-admin-bar-my-account > .ab-item:before {
#wpadminbar #wp-admin-bar-my-account > .ab-item:before,
#wpadminbar #wp-admin-bar-command-palette .ab-icon:before {
display: block;
text-indent: 0;
font: normal 32px/1 dashicons;
Expand All @@ -907,6 +927,10 @@ html:lang(he-il) .rtl #wpadminbar * {
-moz-osx-font-smoothing: grayscale;
}

#wpadminbar #wp-admin-bar-command-palette .ab-icon:before {
left: 0;
}

#wpadminbar #wp-admin-bar-appearance {
margin-top: 0;
}
Expand Down Expand Up @@ -1013,7 +1037,8 @@ html:lang(he-il) .rtl #wpadminbar * {
#wpadminbar li#wp-admin-bar-new-content,
#wpadminbar li#wp-admin-bar-edit,
#wpadminbar li#wp-admin-bar-comments,
#wpadminbar li#wp-admin-bar-my-account {
#wpadminbar li#wp-admin-bar-my-account,
#wpadminbar li#wp-admin-bar-command-palette {
display: block;
}

Expand Down Expand Up @@ -1044,7 +1069,8 @@ html:lang(he-il) .rtl #wpadminbar * {
#wpadminbar #wp-admin-bar-comments,
#wpadminbar #wp-admin-bar-new-content,
#wpadminbar #wp-admin-bar-edit,
#wpadminbar #wp-admin-bar-my-account {
#wpadminbar #wp-admin-bar-my-account,
#wpadminbar #wp-admin-bar-command-palette {
position: static;
}

Expand Down
Loading