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. View the following articles for information on how to create a Shell user and log into your server to run these commands.

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               Adds, removes, fetches, and flushes the WP Object Cache object.
  cap                 Adds, removes, and lists capabilities of a user role.
  cli                 Review current WP-CLI info, check for updates, or see defined aliases.
  comment             Creates, updates, deletes, and moderates comments.
  config              Generates and reads the wp-config.php file.
  core                Downloads, installs, updates, and manages a WordPress installation.
  cron                Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
  db                  Performs basic database operations using credentials stored in wp-config.php.
  dh-find-check       Combines finding and checking whether the installation is still hosted.
  doctor              Diagnose what ails WordPress.
  embed               Inspects oEmbed providers, clears embed cache, and more.
  eval                Executes arbitrary PHP code.
  eval-file           Loads and executes a PHP file.
  export              Exports WordPress content to a WXR file.
  find                Find WordPress installations on the filesystem.
  help                Get help on WP-CLI, or on a specific command.
  host-check          Checks hosting status for WordPress installation.
  import              Imports content from a given WXR file.
  language            Installs, activates, and manages language packs.
  media               Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
  menu                Lists, creates, assigns, and deletes the active theme's navigation menus.
  network             Perform network-wide operations.
  option              Retrieves and sets site options, including plugin and WordPress settings.
  package             Lists, installs, and removes WP-CLI packages.
  php-compat          Scan WordPress, plugins and themes for PHP version compatibility.
  plugin              Manages plugins, including installs, activations, and updates.
  post                Manages posts, content, and meta.
  post-type           Retrieves details on the site's registered post types.
  profile
  reinstall           Reinstalls WordPress core, themes, and plugins.
  rewrite             Lists or flushes the site's rewrite rules, updates the permalink structure.
  role                Manages user roles, including creating new roles and resetting to defaults.
  scaffold            Generates code for post types, taxonomies, plugins, child themes, etc.
  search-replace      Searches/replaces strings in the database.
  server              Launches PHP's built-in web server for a specific WordPress installation.
  shell               Opens an interactive PHP console for running and testing PHP code.
  sidebar             Lists registered sidebars.
  site                Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation.
  super-admin         Lists, adds, or removes super admin users on a multisite installation.
  taxonomy            Retrieves information about registered taxonomies.
  term                Manages taxonomy terms and term meta, with create, delete, and list commands.
  theme               Manages themes, including installs, activations, and updates.
  transient           Adds, gets, and deletes entries in the WordPress Transient Cache.
  user                Manages users, along with their roles, capabilities, and meta.
  widget              Manages widgets, including adding and moving them within sidebars.

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:

Plugins

Installing a plugin

[server]$ wp plugin install PLUGIN_NAME

Activating a plugin

[server]$ wp plugin activate PLUGIN_NAME

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

Themes

Installing a theme

[server]$ wp theme install THEME_NAME

Deactivating a theme

[server]$ wp theme deactivate THEME_NAME

You must then activate a different theme:

[server]$ wp theme activate THEME_NAME

Users

Creating users

View a list of all current users:

[server]$ wp user list

Create a new username while assigning its email and role:

[server]$ wp user create newusername support@dreamhost.com --role=administrator

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

Deleting a user

View a list of all current users:

[server]$ wp user list

Delete the user based on its name:

[server]$ wp user delete username
--reassign parameter not passed. All associated posts will be deleted. Proceed? [y/n] y

Flushing your cache

Run this to flush your cache:

[server]$ wp cache flush

Updating

Re-updating core files

[server]$ wp core update

Forcing the DB upgrade to run

[server]$ wp core update-db

Forcefully downloading all core files

[server]$ wp core download --force

Updating the 'home' url

[server]$ wp option update home http://www.example.com

Updating the 'siteurl' url

[server]$ wp option update siteurl http://www.example.com

See also

Did this article answer your questions?

Article last updated PST.