Command System API Reference
2026-03-018 min read
Command System API Reference
The Sera Command System allows spoke plugins to register, execute, and schedule commands through the hub.
Registering Commands
php
add_filter('sera_commands', function($commands) {
$commands['my_command'] = [
'name' => 'My Command',
'description' => 'Does something useful',
'callback' => 'my_command_handler',
'spoke' => 'my-plugin-slug',
'args' => [
'target' => [
'type' => 'string',
'description' => 'The target to process',
'required' => true,
],
'force' => [
'type' => 'boolean',
'description' => 'Force execution',
'default' => false,
],
],
];
return $commands;
});
function my_command_handler($args) {
$target = $args['target'];
$force = $args['force'] ?? false;
// Do work...
return [
'status' => 'success',
'message' => "Processed {$target}",
'data' => $results,
];
}
add_filter('sera_commands', function($commands) {
$commands['my_command'] = [
'name' => 'My Command',
'description' => 'Does something useful',
'callback' => 'my_command_handler',
'spoke' => 'my-plugin-slug',
'args' => [
'target' => [
'type' => 'string',
'description' => 'The target to process',
'required' => true,
],
'force' => [
'type' => 'boolean',
'description' => 'Force execution',
'default' => false,
],
],
];
return $commands;
});
function my_command_handler($args) {
$target = $args['target'];
$force = $args['force'] ?? false;
// Do work...
return [
'status' => 'success',
'message' => "Processed {$target}",
'data' => $results,
];
}
Executing Commands
From PHP
php
if (function_exists('sera_execute_command')) {
$result = sera_execute_command('my_command', [
'target' => 'homepage',
'force' => true,
]);
}
if (function_exists('sera_execute_command')) {
$result = sera_execute_command('my_command', [
'target' => 'homepage',
'force' => true,
]);
}
From REST API
POST /wp-json/sera/v1/commands/execute
Content-Type: application/json
{
"command": "my_command",
"args": {
"target": "homepage",
"force": true
}
}
POST /wp-json/sera/v1/commands/execute
Content-Type: application/json
{
"command": "my_command",
"args": {
"target": "homepage",
"force": true
}
}
Scheduling Commands
One-Time Schedule
php
sera_schedule_command('my_command', [
'target' => 'all-pages',
], strtotime('+1 hour'));
sera_schedule_command('my_command', [
'target' => 'all-pages',
], strtotime('+1 hour'));
Recurring Schedule
php
sera_schedule_recurring_command('my_command', [
'target' => 'all-pages',
], 'daily', '02:00');
sera_schedule_recurring_command('my_command', [
'target' => 'all-pages',
], 'daily', '02:00');
Chained Commands
Execute multiple commands in sequence:
php
sera_chain_commands([
['command' => 'sentinel_scan', 'args' => ['scope' => 'full']],
['command' => 'pulse_health_check', 'args' => []],
['command' => 'sitemap_rebuild', 'args' => ['force' => true]],
]);
sera_chain_commands([
['command' => 'sentinel_scan', 'args' => ['scope' => 'full']],
['command' => 'pulse_health_check', 'args' => []],
['command' => 'sitemap_rebuild', 'args' => ['force' => true]],
]);
Each command in the chain receives the previous command's result as an additional previous_result argument.
Built-In Commands
| Command | Spoke | Description |
|---|---|---|
sentinel_scan | Sentinel | Run malware scan |
sentinel_firewall_refresh | Sentinel | Reload firewall rules |
pulse_health_check | Pulse | Run health check |
pulse_db_optimize | Pulse | Optimize database |
pulse_cron_cleanup | Pulse | Clean stuck cron jobs |
writer_ai_generate | AI Writer | Generate content |
sitemap_rebuild | AI Sitemap | Rebuild sitemap |
sitemap_indexnow_submit | AI Sitemap | Submit URLs via IndexNow |
cls_pro_scan | CLS Guard Pro | Run CLS scan |
cls_pro_apply_fixes | CLS Guard Pro | Apply auto-generated fixes |