This post is part of a series designed to help developers who are just starting out understand some basics and how they relate to WordPress. This sixth post is about WP-CLI, which stands for WordPress Command Line Interface. If you’ve ever worked with Drupal’s command line tool Drush then it should be easy to learn. If not, you have nothing to fear. We’ll walk you through the basics and provide a video on how to get started hands-on.
WP-CLI is offered on our VPS plans and above (since it requires SSH access) and allows you to administer your WordPress install using shell commands. You can do quite a bit with WP-CLI, including managing posts, comments, media (images & video), plugins, themes, rewrite rules, user roles, and more. It’s a quite powerful little tool. The whole idea and end result is that you no longer have to continually toggle between your browser where WordPress lives and your terminal window to make changes using the command line.
In addition to the commands available, WP-CLI also offers a built-in help system which is nice. You can simply use the command wp help to see a list of all the top-level subcommands. Furthermore, you can dive deeper by asking the system for information about specific subcommands. For example, you could type wp help plugin to get information on what you can do in terms of managing them from the command line as well as a list of the specific plugin subcommands. Not enough detail? You can even query about certain aspects such as wp help plugin install to get information about just that.
Normally you’d have to mess with finding the download and installing it to get up and running, but since it’s pre-loaded on our VPS/Enterprise plans, you get to skip that step and can focus your time and energy on the important stuff like learning the commands. Let’s delve into some basic commands that will help you get started with WP-CLI.
First off, you can use the command wp core download to download the latest version of WordPress. If you already have WordPress installed and want to update it, you can use the wp core update command.
To install a new plugin, you can use wp plugin install plugin-name. For example, wp plugin install akismet will install the Akismet plugin. If you want to activate a plugin, you can use wp plugin activate plugin-name.
Suppose you want to create a new post, you can do so with the wp post create command. For instance, wp post create –post_type=post –post_title=’A sample post’ –post_status=publish will create a new post with the title ‘A sample post’ and publish it.
For managing users, wp user commands are quite useful. For example, wp user list will list all the users on your WordPress site. If you want to create a new user, you can use wp user create username email@domain.com.
These are just a few examples of what you can do with WP-CLI. There are many more commands which you can explore with the help of the wp help command.
The official site for WP-CLI is located here, and you can find the list of default commands here. Additionally, here’s a video for the hands-on approach now that you’re familiar with what WP-CLI is and how it can help…