A Command-Line Interface for WordPress
Currently, there is only one way of talking to a WordPress installation: HTTP requests. Whether you use a web browser, an XML-RPC application or just
wget, it’s still just HTTP underneath.
But what about when said WordPress installation is on the same machine you’re on? More to the point, what if said machine was running an operating system which supported an UNIX shell?
Well, for one thing, you wouldn’t need to worry about cookie-based authentication, since you can already do whatever you want with that installation, if you can read it’s
All that’s needed is some code to glue the command prompt to WordPress. And that’s exactly what wp-cli does. It allows you to control WordPress through the command-line.
A few examples of built-in commands:
# Activate a newly installed theme on a particular site in a multisite setup wp theme activate my-new-theme --blog=fooblog.example.com # Get the value of a certain option wp option get my_option
Now why would you want to do this?
Firstly, if you’re a heavy bash user, it might be more comfortable for you to install a plugin or update Core from the command line.
But the real value in this is automation and seamless integration with other tools: cron jobs, deployment scripts etc.
There have been a few attempts of creating such a tool in the past, but they lacked a critical feature: extensibility. To add a new command to wp-cli, you just need to write a plain PHP class and register it with
There already are several popular plugins that work with wp-cli. For example, if you’re using WP Super-Cache, you can run the following command:
wp super-cache flush
There’s a list of all the community commands on the wiki.
Note that, as of this writing, the wp-cli project is less than a month old. It was started by Andreas Creten and I’m a collaborator. If you would like to get involved, feel free to jump in on github: https://github.com/wp-cli/wp-clicomments powered by Disqus