WP-CLIWP-CLI WP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way. The project page is http://wp-cli.org/ https://make.wordpress.org/cli/ has a series of global parameters (e.g. --path=<path> and --user=<user>) which work with all commands. They are called global parameters because they affect how WP-CLI interacts with WordPress, and have the same behavior across all commands.
# `--user=<user>` sets request to a specific WordPress user
$ wp --user=wpcli eval 'echo wp_get_current_user()->user_email;'
[email protected]
For repeated usage, WP-CLI can also read options from a YAML configuration file (e.g. wp-cli.yml). WP-CLI automatically discovers configuration files on the filesystem based on rules defined below. These configuration files enable specifying default values for both global parameters and subcommand-specific arguments.
# WordPress develop includes a `wp-cli.yml` to enable easy use of WP-CLI
$ pwd
/srv/www/wordpress-develop.dev
$ cat wp-cli.yml
path: src/
Arguments are interpreted following an order of precedence, from highest priority to lowest:
- Command-line arguments.
wp-cli.local.ymlfile inside the current working directory (or upwards).wp-cli.ymlfile inside the current working directory (or upwards).~/.wp-cli/config.ymlfile (path can be changed by setting theWP_CLI_CONFIG_PATHenvironment variable).- WP-CLI defaults.
Global parameters
The table below lists the available arguments (specified on the command-line) and options (specified in the configuration file).
| Description | Argument | Option |
|---|---|---|
|
Path to the WordPress files. Default value: null
|
--path=<path>
|
path: <path>
|
|
Perform operation against a remote server over SSHSSH Secure SHell – a protocol for securely connecting to a remote system in addition to or in place of a password.. Default value: null
|
--ssh=[<user>@]<host>[:<port>][<path>]
|
ssh: [<user>@]<host>[:<port>][<path>]
|
|
Perform operation against a remote WordPress install over HTTPHTTP HTTP is an acronym for Hyper Text Transfer Protocol. HTTP is the underlying protocol used by the World Wide Web and this protocol defines how messages are formatted and transmitted, and what actions Web servers and browsers should take in response to various commands.. Default value: null
|
--http=<http>
|
http: <http>
|
|
Pretend request came from given URLURL A specific web address of a website or web page on the Internet, such as a website’s URL www.wordpress.org. In multisiteMultisite Multisite is a WordPress feature which allows users to create a network of sites on a single WordPress installation. Available since WordPress version 3.0, Multisite is a continuation of WPMU or WordPress Multiuser project. WordPress MultiUser project was discontinued and its features were included into WordPress core.https://codex.wordpress.org/Create_A_Network., this argument is how the target site is specified. Default value: null
|
--url=<url>
|
url: <url>
|
|
Set the WordPress user. Default value: null
|
--user=<id|login|email>
|
user: <id|login|email>
|
|
Skip loading all or some plugins. Note: mu-plugins are still loaded. Default value: ""
|
--skip-plugins[=<plugin>]
|
skip-plugins: <list>
|
|
Skip loading all or some themes. Default value: ""
|
--skip-themes[=<theme>]
|
skip-themes: <list>
|
|
Skip loading all installed packages. Default value: false
|
--skip-packages
|
skip-packages: <bool>
|
|
Load PHPPHP PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. https://www.php.net/manual/en/preface.php. file before running the command (may be used more than once). Default value: []
|
--require=<path>
|
require: <path>
|
|
Execute PHP code before running the command (may be used more than once). Default value: []
|
--exec=<php-code>
|
exec: <php-code>
|
|
Load WordPress in a given context. Default value: auto
|
--context[=<context>]
|
context: <context>
|
|
(Sub)commands to disable. Default value: []
|
Not available as a flag |
disabled_commands: <list>
|
|
Whether to colorize the output. Default value: "auto"
|
--[no-]color
|
color: <bool>
|
|
Show all PHP errors; add verbosity to WP-CLI bootstrap. Default value: false
|
--debug[=<group>]
|
debug: <group>
|
|
Prompt the user to enter values for all command arguments, or a subset specified as comma-separated values. Default value: false
|
--prompt[=<assoc>]
|
Not available as an option |
|
Suppress informational messages. Default value: false
|
--quiet
|
quiet: <bool>
|
|
List of ApacheApache Apache is the most widely used web server software. Developed and maintained by Apache Software Foundation. Apache is an Open Source software available for free. Modules that are to be reported as loaded. Default value: []
|
Not available as a flag |
apache_modules: <list>
|
Config files
WP-CLI can automatically discover and read options from a few configuration file types (when present):
wp-cli.local.ymlfile inside the current working directory (or upwards).wp-cli.ymlfile inside the current working directory (or upwards).~/.wp-cli/config.ymlfile (path can be changed by setting theWP_CLI_CONFIG_PATHenvironment variable).
Besides the global parameters described above, configuration files can also contain defaults for any subcommand, as well as aliases to one or more WordPress installs.
Here’s an annotated example wp-cli.yml file:
# Global parameter defaults
path: wp-core
url: http://example.com
user: admin
color: false
disabled_commands:
- db drop
- plugin install
require:
- path-to/command.php
# Subcommand defaults (e.g. `wp config create`)
config create:
dbuser: root
dbpass:
extra-php: |
define( 'WP_DEBUG', true );
define( 'WP_POST_REVISIONS', 50 );
# Aliases to other WordPress installs (e.g. `wp @staging rewrite flush`)
# An alias can include 'user', 'url', 'path', 'ssh', or 'http'
@staging:
ssh: [email protected]
user: wpcli
path: /srv/www/staging.wp-cli.org
@production:
ssh: [email protected]:2222
user: wpcli
path: /srv/www/wp-cli.org
# Aliases can reference other aliases to create alias groups
# Alias groups can be nested
@both:
- @staging
- @production
# '_' is a special value denoting configuration options for this wp-cli.yml
_:
# Merge subcommand defaults from the upstream config.yml, instead of overriding
merge: true
# Inherit configuration from an arbitrary YAML file
inherit: prod.yml
Remote (SSH) configuration
Using the ssh option, WP-CLI can be configured to run on a remote system rather than the current system. Along with the SSH protocol, WP-CLI also supports connecting to Docker containers (including docker-compose) and Vagrant VMs.
The connection type can be passed via the scheme of the --ssh parameter or ssh option.
Supported types are:
docker:[<user>@]<container_id>– Runs WP-CLI in a running Docker container viadocker exec [--user <user>] <container_id> ...docker-compose:[<user>@]<container_id>– Runs WP-CLI in a running Docker container viadocker-compose exec [--user <user>] <container_id> ...docker-compose-run:[<user>@]<container_id>– Runs WP-CLI in a new Docker container viadocker-compose run [--user <user>] <container_id> ...vagrant– Runs WP-CLI in a running Vagrant VM viavagrant ssh ...[<user>@]<host>[:<port>](ssh) – Runs WP-CLI on a remote machine through an SSH connection viassh [-p <port>] [<user>@]<host> ...
All connection types support an optional path suffix to specify a directory to cd to before running WP-CLI;