Skip to content

Abstraction for registering self-contained WP-CLI commands

Notifications You must be signed in to change notification settings

sterner-stuff/wp-cli-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

WP_CLI_Helper

A small WP_CLI abstract to ensure all command responsibilities and information are self-contained.

What does this solve

Wraps your command's namespace and registration arguments into a single class. Turns:

$namespace = 'hello';
$args = [
    'shortdesc' => 'Says hello',
];
WP_CLI::add_command($namespace, 'MyCommand', $args);

into

MyCommand::register();

Usage

Your command class should follow the conventions laid out in the WP-CLI docs for defining a command as a class. Addtionally, it should extend this helper, define its namespace, optionally define an $args property, and either the __invoke() magic method or class methods, which are registered by WP-CLI as sub-commands.

<?php 

class MyCommand extends \SternerStuff\WP_CLI_Helper\WP_CLI_Command {

    public $namespace = 'say';

    public function hello()
    {
        echo 'Hello';
    }

}

About

Abstraction for registering self-contained WP-CLI commands

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages