Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayWood/30f10428a26de7a2654d3e8bc7bb45da to your computer and use it in GitHub Desktop.
Save JayWood/30f10428a26de7a2654d3e8bc7bb45da to your computer and use it in GitHub Desktop.
A live template for PHPStorm to create WP-CLI commands on-the-fly.
namespace $var1$;
use Exception;
use WP_CLI;
class $class$ {
/**
* The WP-CLI Command Arguments
*
* Nothing to see here.
*
* @var array
*/
private $args, $assoc_args;
/**
* Rather or not to do the actual import.
* @var bool
*/
private $is_wet_run = false;
/**
* @var object Instance of the progress bar.
*/
private $progress;
/**
* @param array $args
* @param array $assoc_args
*
* @throws WP_CLI\ExitException
*/
public function __invoke( $args, $assoc_args ) {
// Properties so it can be reused later.
$this->args = $args;
$this->assoc_args = $assoc_args;
$this->is_wet_run = ! empty( $assoc_args['wet'] );
}
}
try {
WP_CLI::add_command( '$command$', __NAMESPACE__ . '\\$class$', [
'shortdesc' => '$description$',
'synopsis' => [
[
'type' => 'flag',
'name' => 'wet',
'optional' => true,
'description' => 'Actually runs the command.',
],
],
] );
} catch ( Exception $e ) {
die( $e->getMessage() ); // @codingStandardsIgnoreLine Do not complain about escaping an exception.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment