Add guidance on where to place custom WP-CLI commands#631
Merged
swissspidy merged 2 commits intomainfrom Mar 17, 2026
Merged
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve documentation for adding custom wp-cli customizations
docs: Add guidance on where to place custom WP-CLI commands
Mar 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds missing “where should I put this code?” guidance for WP-CLI custom commands by documenting a global require approach in the Commands Cookbook and linking to it from the WP_CLI::add_command() reference page.
Changes:
- Documented registering personal/global commands via
requirein~/.wp-cli/config.yml, plus per-invocation alternatives (--require,WP_CLI_REQUIRE). - Added a cross-link from the
WP_CLI::add_command()internal API reference page to the Commands Cookbook. - Fixed a small typo in the Commands Cookbook (“produce” → “produced”).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| guides/commands-cookbook.md | Adds a new “Adding commands globally” section and corrects a typo in Distribution. |
| references/internal-api/wp-cli-add-command.md | Adds a pointer to the Commands Cookbook for placement guidance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+497
to
+501
| 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 |
|
|
||
| Any commands registered in that file will be globally available whenever you run WP-CLI. This is great for personal helper commands that you want available across all your WordPress projects. | ||
|
|
||
| You can also pass the `--require=<path>` flag on the command line, or set the `WP_CLI_REQUIRE` environment variable, to load a custom PHP file for a single invocation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users had no clear documentation on where to register personal/global WP-CLI customizations — the
WP_CLI::add_command()reference page showed how to register commands but not where to put the code.Changes
guides/commands-cookbook.md— Added "Adding commands globally" section covering therequireapproach in~/.wp-cli/config.yml:Also mentions
--require=<path>CLI flag andWP_CLI_REQUIREenv var for per-invocation use. Fixed pre-existing typo ("produce" → "produced") in the Distribution section.references/internal-api/wp-cli-add-command.md— Added a forward reference to the Commands Cookbook so readers landing on the API page are directed to placement guidance.Original prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.