WP-CLI cuts down on WordPress development time and allows you to work smarter. Find out why, and learn how to get started.
When I was getting started as a developer, I kept hearing about how much easier my life would be if I would just use the command line. But even though I knew it would help, I was so intimidated—and besides, I knew how to do everything I wanted to via the dashboard. It seemed like an added layer of complexity and I was busy building sites for clients!
It was a classic example of working harder, not smarter. I eventually needed to use the command line and once I did, I regretted all that time I spent waiting for the WordPress dashboard to load. I could have saved hours (dare I say days?) of development time if I'd started using WP-CLI sooner. It’s enabled me to be a better developer.
Watch the recording: Tara King talks to Alain Schlesser, maintainer of WP-CLI, about how this elegant, powerful tool can supercharge your workflow.
What Is WP-CLI?
WP-CLI is the WordPress Command Line Interface, and you can use it to install a WordPress site, add new plugins or themes, create and modify users… and so much more. Anything you can do via the dashboard, you can do with WP-CLI—and WP-CLI has a few tricks that might make the admin dashboard a little jealous.
Getting Started With WP-CLI on Pantheon
It's really easy to try out WP-CLI on Pantheon—it's already installed on the platform.
You'll need to install Terminus—Terminus runs on your local machine, and will run WP-CLI remotely on your Pantheon sites. The command structure when using Terminus is slightly different than the default WP structure, and is covered in our documentation.
If you want to use WP-CLI locally, helpful instructions live on the WP-CLI documentation.
Top 5 WP-CLI Commands
Here are five basic commands you can try today to get started with WP-CLI.
Install and Activate Plugins
wp plugin install pantheon-advanced-page-cache --activate
This one-line command will install and activate the Pantheon Advanced Page Cache plugin. Easy enough, right?
wp plugin deactivate plugin-name
You can also deactivate a plugin—a great way to recover a site when a plugin or theme has brought your dashboard down. Just disable the plugin using WP-CLI, and you're back in business.
Change User Passwords
wp user update 1 --user_pass=<password>
Ever need to change a user password? WP-CLI has your back. You can also create new users, modify user roles, and more.
wp plugin list --update=available
This command will show you a list of all plugins on your site—and with the addition of the --update=available flag, you'll get only the plugins waiting to be updated.
Search and Replace
wp search-replace "://test.example.com" "://live.example.com" --all-tables --verbose
My personal favorite WP-CLI command is also an example of how WP-CLI can do more than the admin dashboard. If you're moving a site from test to live, this WP-CLI command will search your database to replace any URLs stored there, saving you a ton of time and heartache. It's actually built into our Pantheon workflows so you never have to worry about URLs in the database when you clone from one environment to the next.
Learn More About WP-CLI
I recently hosted a webinar with Alain Schlesser (maintainer of WP-CLI) on getting started with WP-CLI. We talk through the basics of installing WP-CLI, before demonstrating the commands above and a few more.
We've just scratched the surface of what's possible with WP-CLI. Once you start using one-off commands with WP-CLI, it's just a few more steps to write a WP-CLI script to automate your work… and then you'll really be saving time.
We have some helpful resources in our documentation, too:
You might also like: