Site icon Tidy Repo

WP-CLI

Out of the box, WordPress is simple to use for people of any web experience. But if you work as a WordPress developer, you’ll often find yourself doing the same things again and again. Creating new blogs, upgrading your site, running plugin tests and the like. You’re also probably familiar with the command line because hey, you’re a developer. That’s where WP-CLI can help you out.

What’s It Do?

WP-CLI gives you access to a fairly long list of command line tools for you to use. What this really means is that you can execute basic tasks on the fly without having to enter the WordPress admin panel, and you can automate tasks by simply stringing them together in a text file.

I won’t go into all the details of the commands, but here are a few examples

This list only scratches the surface of what WP-CLI can do, but it should give you an indication of how much control you get. You can install, manage, update and modify a WordPress all without ever having to log in to the backend.

How’s It Work?

Just note, I am assuming you have some experience on the command line if you are reading this far. If you aren’t, check out this LifeHacker post.

There are a few dependencies for wp-cli, but you should be using them if you are planning to install WordPress. You’ll want a UNIX-like environment (the site recommends OS X, Linux, FreeBSD, etc.). You really just need access to your command line. You’ll also want to have PHP 5.3.2 or later installed. In addition, install Composer for dependency management (though this will be handled by the installer if you do not have it).

From your command line, in your root directory, run


curl https://raw.github.com/wp-cli/wp-cli.github.com/master/installer.sh | bash

This will launch the wp-cli installer which will automatically install all of the dependencies that it needs to run. Assuming everything goes right, you will be ready to use wp-cli. If it does not, I would check the GitHub issues page to see if anyone has had a similar problem.

In order to make the “wp” command run properly, you’ll have to add this line to your .bash_profile file.

# WP-CLI Bash completions
source $HOME/.wp-cli/vendor/wp-cli/wp-cli/utils/wp-completion.bash

To start using WP-CLI either create a new directory, or cd into the directory that you want to set-up WordPress. From there, just use WP-CLI’s commands to control your WordPress install. There is a long list of things to do but just type any command followed by the word “help” to find out exactly what it does. And check out the post on Wp Tuts+ written by the plugins creator, Scribu, for a basic rundown of what this plugin can do.

A list of possible commands

Costs, Caveats, Etc.

WP-CLI is well-maintained but it is not incredibly well-documented. If you don’t have experience using the command line and some basic experience with PHP development, then I would not recommend this. You’ll end up swimming in a sea of problems. When I first tried setting this up on my Mac, I had to backtrack several times to get everything right, but I am a man of little experience.

If you are on a Mac, I would consider using Vagrant for setting up your WordPress installs in a local environment. That way everything stays contained, and you can always start from scratch if you need to. I’ve been using the Varying Vagrant Vagrants package from Jeremy Felt of 10up and it has worked like a charm. WP-CLI, as well as many other tools, come pre-installed with the vagrant box. All you have to do is pull the repository off of Github.

Resources

Exit mobile version