Toolbar: Add command palette trigger button.
Props wildworks, hmbashar, bpayton, mcsf, joedolson, sabernhardt, westonruter. See #64672. Built from https://develop.svn.wordpress.org/trunk@61912 git-svn-id: http://core.svn.wordpress.org/trunk@61194 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -934,6 +934,44 @@ 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' )
|
||||
: _x( 'Ctrl+K', 'keyboard shortcut to open the command palette' );
|
||||
$title = sprintf(
|
||||
'<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(
|
||||
'id' => 'command-palette',
|
||||
'title' => $title,
|
||||
'href' => '#',
|
||||
'meta' => array(
|
||||
'class' => 'hide-if-no-js',
|
||||
'onclick' => 'wp.data.dispatch( "core/commands" ).open(); return false;',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds "Add New" menu.
|
||||
*
|
||||
|
||||
@@ -661,6 +661,9 @@ class WP_Admin_Bar {
|
||||
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 );
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '7.0-beta3-61890';
|
||||
$wp_version = '7.0-beta3-61912';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user