mirror of
https://fast.feibisi.com/https://github.com/wp-cli/scaffold-command.git
synced 2025-10-04 17:01:28 +08:00
Edited README.md via GitHub
This commit is contained in:
parent
9b03371076
commit
fa29738051
1 changed files with 3 additions and 53 deletions
56
README.md
56
README.md
|
@ -11,9 +11,8 @@ Installing
|
|||
|
||||
**Via package manager:**
|
||||
|
||||
Ubuntu, Debian: [.deb package](https://github.com/downloads/andreascreten/wp-cli/wp-cli_0.1.deb)
|
||||
|
||||
On Mac, install [Homebrew](http://mxcl.github.com/homebrew/) and run `brew install wp-cli`.
|
||||
* Ubuntu, Debian: [.deb package](https://github.com/downloads/andreascreten/wp-cli/wp-cli_0.1.deb)
|
||||
* Mac: install [Homebrew](http://mxcl.github.com/homebrew/) and run `brew install wp-cli`.
|
||||
|
||||
**From source:**
|
||||
|
||||
|
@ -112,56 +111,7 @@ Adding commands
|
|||
---------------
|
||||
|
||||
Adding commands to wp-cli is very easy. You can even add them from within your own plugin.
|
||||
|
||||
Each command has its own class, the methods of that class are the sub commands of the command. The base class for the commands is the abstract `WP_CLI_Command`, it handles some essential functionality (like default help for your command).
|
||||
|
||||
You can add new commands to the `commands/community` folder in the wp-cli plugin, they will be auto-loaded on startup. You can also add commands from within your plugins by just calling the wp-cli hooks from there.
|
||||
|
||||
A wp-cli class is structured like this:
|
||||
|
||||
``` php
|
||||
<?php
|
||||
/**
|
||||
* Implement example command
|
||||
*
|
||||
* @package wp-cli
|
||||
* @subpackage commands/community
|
||||
* @author Andreas Creten
|
||||
*/
|
||||
class ExampleCommand extends WP_CLI_Command {
|
||||
/**
|
||||
* Example method
|
||||
*
|
||||
* @param string $args
|
||||
* @return void
|
||||
*/
|
||||
function example($args = array()) {
|
||||
// Print a success message
|
||||
WP_CLI::success('Success message');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To register this class under the `example` command, add the following line to the top of your command class file.
|
||||
|
||||
``` php
|
||||
<?php
|
||||
// Add the command to the wp-cli
|
||||
WP_CLI::addCommand('example', 'ExampleCommand');
|
||||
```
|
||||
|
||||
This will register the comand `wp example` and the subcommand `wp example example`. If you run `wp example example`, the text `Success: Success message` will be printed to the command line and the script will end.
|
||||
|
||||
You can take a look at the example command file in `commands/community/example.php` for more details. For the ways to interact with the command line, you should take a look at the WP_CLI class in the `class-wp-cli.php` file.
|
||||
|
||||
If you want to register the command from within your plugin you might want to add a check to see if wp-cli is running. By doing this you can implement your wp-cli command by default, even if wp-cli is not installed on the WordPress installation. You can use the `WP_CLI` constant to check if wp-cli is running:
|
||||
|
||||
```php
|
||||
<?php
|
||||
if(defined('WP_CLI') && WP_CLI) {
|
||||
// Define and register your command in here
|
||||
}
|
||||
```
|
||||
You can find more information about adding commands in the [Commands Cookbook](https://github.com/andreascreten/wp-cli/wiki/Commands-Cookbook) on our Wiki.
|
||||
|
||||
**Please share the commands you make, issue a pull request to get them included in wp-cli by default.**
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue