Palette commands with steps
Since version 2.11.0 a command in the Addofy palette can ask for values before it runs. Each param is a step in the palette.
Param types
order,productanduserpick an id from the search results.choiceshows the options you give.texttakes what the user typed.
Run through a REST route
Add the command with the adba_commands filter. With an endpoint, the palette posts the values to that route below adba/v1 in the background. Placeholders like {order} are filled in, and the rest is sent as the body. The text in done shows as a toast.
add_filter( 'adba_commands', function ( $commands ) {
$commands[] = array(
'id' => 'myplugin-priority',
'label' => 'Set order priority',
'keywords' => array( 'order', 'priority' ),
'params' => array(
array( 'name' => 'order', 'type' => 'order', 'label' => 'Which order?' ),
array( 'name' => 'level', 'type' => 'choice', 'label' => 'Priority', 'options' => array( 'high' => 'High', 'low' => 'Low' ) ),
),
'endpoint' => 'myplugin/orders/{order}/priority', // Your own route below adba/v1.
'done' => 'Priority saved.',
);
return $commands;
} );
Register the route with register_rest_route( 'adba/v1', '/myplugin/...' ).
Run in JavaScript
Instead of an endpoint you can register the command in JavaScript. run() gets the values:
adba.commands.register( { id: 'myplugin-priority', label: 'Set order priority', params: [ /* same params */ ], run( values ) {} } );
Behavior in the palette
screensshows a command only on those screens, at the top of the palette.context(orderorproduct) fills in the first param of that type with the object of the edit screen.- Backspace in an empty input goes back a step. Esc goes back to the command list.
- The last eight commands show under Recent.
- The event
palette:run({ command, values }) fires when a palette command runs.