Skip to content

Commit da91fd9

Browse files
Merge pull request wp-cli#269 from wp-cli/3671-subcommand
Mention registering commands as subcommands of existing namespaces
2 parents 4b68ad2 + ae6f828 commit da91fd9

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

docs/commands-cookbook/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ Importantly, classes behave a bit differently than functions and closures in tha
103103
* Any public methods on a class are registered as subcommands of the command. For instance, given the examples above, a method `bar()` on the class `Foo` would be registered as `wp foo bar`. But...
104104
* `__invoke()` is treated as a magic method. If a class implements `__invoke()`, the command name will be registered to that method and no other methods of that class will be registered as commands.
105105

106+
All commands can be registered to their own top-level namespace (e.g. `wp foo`), or as subcommands to an existing namespace (e.g. `wp core foo`). For the latter, simply include the existing namespace as a part of the command definition.
107+
108+
```
109+
class Foo_Command {
110+
public function __invoke( $args ) {
111+
WP_CLI::success( $args[0] );
112+
}
113+
}
114+
WP_CLI::add_command( 'core foo', 'Foo_Command' );
115+
```
116+
106117
### Quick and dirty execution
107118

108119
Writing a short script for a one-off task, and don't need to register it formally with `WP_CLI::add_command()`? `wp eval-file` is your ticket ([doc](http://wp-cli.org/commands/eval-file/)).

0 commit comments

Comments
 (0)