Skip to main content

Create a custom WP CLI command

You can create a WP CLI command using WP_CLI::add_command function. Simply also allows you to directly configure your commands by create a class extends AbstractWPCliCommand like this :

app/Commands/MyCommand.php
<?php
use Simply\Core\Command\AbstractWordPressCommand;

class MyCommand extends AbstractWordPressCommand {
static $commandName = 'app:mycommand';
public function execute($args, $assoc_args) {
// ...
}
}

And add the tag wp.command to your class in config/command/mycommand.yaml file :

config/commands.yaml
services:
Namespace\MyCommand:
tags: ['wp.command']

Using CLI

php bin/console simply:make:wpclicommand