In a nutshell, WP-CLI is a command line interface for WordPress that allows you to do everything you can in your admin panel but using commands in your terminal. Your first reaction might be: but why use a command line interface, when you have this neat visual WordPress admin?
After all, posting on your blog through a command line does not look very appealing, unless you are a really hard-core geek. Well, I should admit that I am not that much of a hard-core but it tuned out that WP-CLI can be really handy. Β Here are my three favorite things that I do much easier now that I use WP-CLI:
I get a new project started much easier: with my own WP-CLI autoinstaller
After you install WP-CLI, you will have a regular shell command “wp” that you can use within all sorts of scripts and scheduled tasks. For example, you can make a simple script that installs all the plugins you add when you start a new project, a framework theme if you use any, and so on. Basically, you can make your own . For example, when I start a new WordPress project, I often use this script to save some time installing the most essential plugins and a theme that I love modifying:
wp theme install responsive –activate
wp plugin delete hello
wp plugin install click-go-seo –activate
wp plugin install akismet –activate
wp plugin install wp-example-content –activate
Once I do that, I can start working on the actual site immediately. If you’re creating your sites locally, you can link those commands with your OS and literally create new WordPress instances with a click. Actual commands vary depending on the OS and web server you’re using.
I maintain multiple sites much easier: with a simple automated WP- CLI based script
Another great way to use WP-CLI is to execute maintenance tasks for your sites. Although not many people do it, it’s great to optimize your MySQL database from time to time. Another important thing is to keep your site and plugins up-to-date. This is why, before WordPress 3.7 launched I used to execute this script on a daily basis:
wp db optimize
wp db export daily-before-update.sql
wp core update
wp plugin update-all
wp theme update-all
wp db export daily-after-update.sql
Now, I’ve simply removed the core, plugins and themes update lines and rely on the internal WordPress auto update system for that. Basically, you can schedule database optimization and a backup to be created on a daily basis. However, this is just an example. The actual possible ways to use it are endless.
I troubleshoot WordPress issues much faster
When you have to troubleshoot WordPress sites, WP-CLI is a real gem. For example, if you have to find the reason for the βwhite screen of deathβ you can use WP-CLI to turn off themes and plugins one by one until you pinpoint the reason for the issue. Another great thing about it is that if any WordPress update breaks any of the plugins you rely on, you can use WP-CLI to reverse back to the previous WordPress version until an update for your plugin is released. Here’s how:
Disable/Enable Plugins:
wp plugin deactivate akismet
wp plugin activate akismet
Switching Themes:
wp theme activate twentytwelve
Reverse back to previous WordPress version:
wp core update –version=3.6.1 –force
One of the greatest things about WP-CLI is that itβs extendable. This means that you can write your own command and you can do practically anything. Thereβs already a big list of community commands available.
I really cannot come up with a reason why not to use WP-CLI, so my final advise would be to start using it today. To install WP-CLI on your server, all you need to do is execute a single command that you can get from the project’s official site. For the convenience of our customers, at SiteGround WP-CLI comes preinstalled on all our servers.
If you enjoyed this post, make sure to subscribe to WP Mayor’s RSS feed.