Skip to content

An Intro to WP-CLI

One of the most powerful tools in the WordPress world is the WordPress Command Line Interface or WP-CLI. From user management, to managing plugin and theme updates, WP-CLI can pretty much do anything you need it to do.

User Management

One of the easiest things to do is manage users. From updating email address and display names to user meta, capabilities, and roles. Here’s a quick example on updating a display name for a user.

$ wp user update --display_name="WordPress User"

This will update the user with the email address “” to have a display name of “WordPress User”. Pretty much any information about a user can be changed with the update command.

Plugin Management

Managing plugins can sometimes be a pain because of many factors, but WP-CLI can alleviate some of that. Here’s a quick list of plugins and information about them.

$ wp plugin list

As you can see, we have a few out of date plugins here. Luckily updating those is a breeze.

$ wp plugin update <plugin name>

You can also activate and deactivate plugins easily with:

$ wp plugin activate <plugin name>
$ wp plugin deactivate <plugin name>

Or to simplify it $ wp plugin toggle <plugin name> will just switch the status to the opposite of whatever it currently is.

If you’re deactivating plugins because you have a white screen of death (WSOD), you can still deactivate plugins with the --skip-plugins flag.

$ wp plugin deactivate <plugin name > --skip-plugins

This will stop all plugins from loading and allowed WordPress to deactivate plugins correctly.
Protip: $ wp plugin deactivate --all --skip-plugins

WordPress Core Management

Making sure WordPress core (and plugins/themes) are up to date is one of the best ways to keep yourself a little more safe against vulnerabilities. WP-CLI provides some awesome tools for managing WordPress core.

$ wp core verify-checksums

This is one of my favorite commands. It will check all of your WordPress core files and verify that they haven’t been modified or tampered with. This is extremely useful for fixing hacked sites because it will tell you exactly which file has been changed.

Let’s say your site has been hacked and core files have been modified. $ wp core download --force will download the latest version of all WordPress core files and undo any changes. After this you should probably make sure your themes and plugins are up to date. Sometimes, it takes a professional to make sure all hacks are eliminated.

The Power of WP-CLI

A nifty tool I’ve had the opportunity to work on is called wp-tools, which is a Perl wrapper around WP-CLI commands. One of the features of wp-tools is the ability to update core, themes, and plugins. It does this the right way by first taking a backup of your site and updating the components you specify. If any problems are detected on the site after the upgrades, your site will automatically be restored to the backup. This tool has been battle tested and used to update more than 2 million WordPress installations.

If you have any questions or comments about WP-CLI please leave a comment below or use my Contact Page.

Published inphpWordPress