WordPress wp-cli overview

WordPress Command Line Interface (or, wp-cli ) is installed on all servers at DreamHost. This feature allows you to run WordPress commands from your Shell terminal. For example you can import a database, create a new user, update themes and plugins all using wp-cli.

This article is a quick overview of this service.

Listing available commands

Log in to your server via SSH. Once logged in, make sure you’re in your WordPress site’s directory. In that directory run the following command to print a list of available options:

[server]$ wp

The following available commands display:

SUBCOMMANDS

 cache               Manage the object cache.
 cap                 Manage user capabilities.
 cli                 Get information about WP-CLI itself.
 comment             Manage comments.
 core                Download, install, update and otherwise manage WordPress proper.
 db                  Perform basic database operations.
 eval                Execute arbitrary PHP code after loading WordPress.
 eval-file           Load and execute a PHP file after loading WordPress.
 export              Export content to a WXR file.
 help                Get help on a certain command.
 import              Import content from a WXR file.
 jetpack             Control your local Jetpack installation.
 media               Manage attachments.
 network
 option              Manage options.
 plugin              Manage plugins.
 post                Manage posts.
 rewrite             Manage rewrite rules.
 role                Manage user roles.
 scaffold            Generate code for post types, taxonomies, etc.
 search-replace      Search/replace strings in the database.
 shell               Interactive PHP console.
 site                Perform site-wide operations.
 super-admin         List, add, and remove super admins from a network.
 term                Manage terms.
 theme               Manage themes.
 transient           Manage transients.
 user                Manage users.

GLOBAL PARAMETERS

 --path=<path>
     Path to the WordPress files

 --url=<url>
     Pretend request came from given URL

 --user=<id|login>
     Set the WordPress user

 --skip-plugins[=<plugin>]
     Skip loading all or some plugins

 --require=<path>
     Load PHP file before running the command (may be used more than once)

 --[no-]color
     Whether to colorize the output

 --debug
     Show all PHP errors

 --prompt
     Prompt the user to enter values for all command arguments

 --quiet

Finding more information on a command

To get more information on a specific command, run the --help option. For example:

[server]$ wp plugin --help

This prints a list of available subcommands. For example:

SUBCOMMANDS

 activate          Activate a plugin.
 deactivate        Deactivate a plugin.
 delete            Delete plugin files.
 get               Get a plugin.
 install           Install a plugin.
 is-installed      Check if the plugin is installed.
 list              Get a list of plugins.
 path              Get the path to a plugin or to the plugin directory.
 search            Search the wordpress.org plugin repository.
 status            See the status of one or all plugins.
 toggle            Toggle a plugin's activation state.
 uninstall         Uninstall a plugin.
 update            Update one or more plugins.

You can then combine these with the main command to perform an action. Here is how you’d install a plugin named hello-dolly:

[server]$ wp plugin install hello-dolly
Installing Hello Dolly (1.6)
Downloading install package from https://downloads.wordpress.org/plugin/hello-dolly.1.6.zip...
Unpacking the package...
Installing the plugin...
Plugin installed successfully.

If you now run ‘wp plugin list’, all of your plugins appear:

[server]$ wp plugin list
+--------------------+----------+--------+---------+
| name               | status   | update | version |
+--------------------+----------+--------+---------+
| akismet            | inactive | none   | 3.1.1   |
| dreamobjects       | inactive | none   | 3.5.2   |
| hello-dolly        | inactive | none   | 1.6     |
| hello              | inactive | none   | 1.6     |
| jetpack            | active   | none   | 3.5.3   |
| varnish-http-purge | active   | none   | 3.7.2   |
+--------------------+----------+--------+---------+

Common commands

These popular commands are used most often when debugging:

Deactivating a plugin

[server]$ wp plugin deactivate PLUGIN_NAME
-or-
[server]$ wp plugin toggle NAME

Deactivating installed plugins on multisite network

[server]$ wp plugin toggle NAME --network

Deactivating a theme

[server]$ wp theme deactivate THEME_NAME

You must then activate a different theme:

[server]$ wp theme activate THEME_NAME

Changing a password

List all users to view their user ID#:

[server]$ wp user list

Use that user ID# to update their password:

[server]$ wp user update 3 --user_pass=123456

Flushing your cache

Depending on which plugin you’re using, run one of these to flush your cache:

[server]$ wp cache flush
-or-
[server]$ wp super-cache flush

Re-updating core files

[server]$ wp core update

Forcing the DB upgrade to run

[server]$ wp core update-db

See also

Did this article answer your questions?

Article last updated .