diff --git a/guides/commands-cookbook.md b/guides/commands-cookbook.md index 1945bb1a..9eb93ce6 100644 --- a/guides/commands-cookbook.md +++ b/guides/commands-cookbook.md @@ -490,9 +490,34 @@ Functional tests typically follow this pattern: Convinced? Head on over to [wp-cli/scaffold-package-command](https://github.com/wp-cli/scaffold-package-command) to get started. +## Adding commands globally + +If you want to have custom commands available globally, without needing to create a full plugin or package, you can use WP-CLI's `require` configuration option. + +Edit your [global config file](https://make.wordpress.org/cli/handbook/references/config/) (usually found at `~/.wp-cli/config.yml`) to require a PHP file: + +```yaml +require: + - ~/.wp-cli/commands.php +``` + +Then create the file and add your custom commands: + +```php +` flag on the command line, or set the `WP_CLI_REQUIRE` environment variable, to load a custom PHP file for a single invocation. + ## Distribution -Now that you've produce a command you're proud of, it's time to share it with the world. There are two common ways of doing so. +Now that you've produced a command you're proud of, it's time to share it with the world. There are two common ways of doing so. ### Include in a plugin or theme diff --git a/references/internal-api/wp-cli-add-command.md b/references/internal-api/wp-cli-add-command.md index 35bfd0cd..dd96aaff 100644 --- a/references/internal-api/wp-cli-add-command.md +++ b/references/internal-api/wp-cli-add-command.md @@ -51,6 +51,8 @@ WP_CLI::add_command( 'foo', $foo ); ``` +For guidance on where to place your custom commands (e.g. globally via `~/.wp-cli/config.yml`, in a plugin or theme, or as a standalone package), see the [Commands Cookbook](https://make.wordpress.org/cli/handbook/guides/commands-cookbook/). + *Internal API documentation is generated from the WP-CLI codebase on every release. To suggest improvements, please submit a pull request.*