Make WordPress Core

Changeset 61912


Ignore:
Timestamp:
03/10/2026 07:11:27 PM (8 months ago)
Author:
ellatrix
Message:

Toolbar: Add command palette trigger button.

Props wildworks, hmbashar, bpayton, mcsf, joedolson, sabernhardt, westonruter.
See #64672.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/admin-bar.php

    r60890 r61912  
    936936
    937937/**
     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 */
     947function 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
     975/**
    938976 * Adds "Add New" menu.
    939977 *
  • trunk/src/wp-includes/class-wp-admin-bar.php

    r58748 r61912  
    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() ) {
Note: See TracChangeset for help on using the changeset viewer.