admin管理员组

文章数量:1406001

I want to create a custom WP CLI command and I have read the documentation but I just don't understand for the life of me how this works.

Do I need to declare it before in my config file where they are gonna go?

Is it a PHP file? If so, I need to declare it put it anywhere inside my theme?

Thank you in advance.

I want to create a custom WP CLI command and I have read the documentation but I just don't understand for the life of me how this works.

Do I need to declare it before in my config file where they are gonna go?

Is it a PHP file? If so, I need to declare it put it anywhere inside my theme?

Thank you in advance.

Share Improve this question asked Nov 28, 2019 at 0:09 Marco BerrocaMarco Berroca 633 bronze badges 1
  • 1 there is a chapter "Extending" here github/wp-cli/wp-cli/#extending – Kaperto Commented Nov 28, 2019 at 0:23
Add a comment  | 

1 Answer 1

Reset to default 1

You can put the PHP anywhere in your plugin, or a file that's included into your plugin, the same as you would any other code for extending any part of WordPress in a plugin. The only thing you need to do is check that WP_CLI exists before using any of the WP CLI API:

if ( defined( 'WP_CLI' ) && WP_CLI ) {
    // WP_CLI::add_command etc.
}

本文标签: wp cliWhere do the files of a custom WP CLI Command reside