Make WordPress Core

Opened 16 hours ago

Last modified 16 hours ago

#66322 new enhancement

Command Palette: Add keywords to admin menu commands

Reported by: jdeep Owned by:
Priority: normal Milestone: Awaiting Review
Component: Script Loader Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: administration

Description

The Command Palette registers a command for every admin menu item (#63845), but these commands can only be found by their label. Searching for "favicon", "timezone" or "password" finds nothing, even though Settings > General and Users > Profile are where those are.

The Command Palette has supported keywords since ​Gutenberg #70624. When ​Gutenberg #71476 moved admin navigation to commands generated from the admin menu, there was no longer a way to attach keywords to them. That was listed as one of its trade-offs.

The proposal is that keywords come from PHP, next to the label, url and name that wp_enqueue_command_palette_assets() already sends.

Proposed change

  • A new function, wp_get_admin_menu_command_keywords(), returns keywords for core admin screens, keyed by menu slug.
  • A new filter, admin_menu_command_keywords, lets plugins add keywords for their own pages. They key them by the same $menu_slug they pass to add_menu_page() or add_submenu_page().
  • wp_enqueue_command_palette_assets() adds a keywords list to each top-level and submenu command. Commands without keywords get an empty list.

For example, a plugin could add:

add_filter(
        'admin_menu_command_keywords',
        function ( $keywords ) {
                $keywords['my-shop'] = array( 'orders', 'products' );
                return $keywords;
        }
);

The Gutenberg side, which passes the keywords through to the palette, is in ​Gutenberg #84834.

Change History (1)

This ticket was mentioned in ​PR #14309 on ​WordPress/wordpress-develop by ​@jdeep.


16 hours ago
#1

  • Keywords has-patch has-unit-tests added

Adds keywords to the admin menu commands in the Command Palette, so admin screens can be found by words that are not in their label. For example, "favicon" finds Settings > General and "password" finds Users > Profile.

  • New wp_get_admin_menu_command_keywords() returns keywords for core admin screens, keyed by menu slug. Each keyword is translatable with the command palette keyword context.
  • New admin_menu_command_keywords filter lets plugins add keywords for their own pages, keyed by the $menu_slug they pass to add_menu_page() or add_submenu_page().
  • wp_enqueue_command_palette_assets() adds a keywords list to each top-level and submenu command. Commands without keywords get an empty list.
  • New tests in tests/phpunit/tests/dependencies/wpEnqueueCommandPaletteAssets.php.

The palette uses these keywords once WordPress/gutenberg#84834 is in core. Until then, the keywords are sent but ignored.

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Tracing how the menu commands reach the Command Palette, drafting the implementation and the filter. I reviewed, ran and tested everything.

Note: See TracTickets for help on using tickets.