WP-CLI gives you the ability to manage your WordPress sites through a command-line interface. This is awesome. Many of the things you would have had to open up your WP Dashboard for or use some particular plugin can now be quickly done through the command line.
Installation
You can do this in your development environment, on your staging server, and on production! If you want to be able to run wp-cli from your local installation but through SSH to target another server, you can follow the steps at Smashing Magazine.
Note: The following steps require a UNIX-like environment (OS X, Linux or FreeBSD). If you are a Windows user, you will need a command-line tool such as Cygwin or a virtual machine.
Step 1: Install from the Github Repository
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Step 2: Make the file executable
chmod +x wp-cli.phar
Step 3 (Optional): Create an alias or move the file to make it executable from anywhere
Move the file:
sudo mv wp-cli.phar /usr/local/bin/wp
Create an alias:
mv wp-cli.phar ~/ alias wp='~/wp-cli.phar'
The installation should be complete and you can test whether the wp-cli script is working by typing the following command:
wp --info
Which should output similar to the following:
PHP binary: /usr/bin/php PHP version: 5.5.24 php.ini used: /etc/php.ini WP-CLI root dir: phar://wp-cli.phar WP-CLI global config: /Users/kouratoras/.wp-cli/config.yml WP-CLI project config: WP-CLI version: 0.19.2
My Favorite Uses For WP-CLI
Download latest WordPress files:
wp core download
Updates:
wp core update wp core update-db wp plugin update --all wp theme update --all
Work with users:
wp user list wp role list wp user add-role USER_ID "ROLE"
Using WP-CLI In Your Workflow:
This is where this tool can really save you a lot of time. Whenever I rsync my files to staging or to production or in reverse, I will use the following command to change all instances of the base URL:
wp search-replace "OLD URL" "NEW URL"
If you ever need to do a test run, just add the –dry-run flag to any command. For example
wp search-replace --dry-run "yahoo.com" "google.com"