In the latter months of 2019, I began to explore more earnestly the command line tool for WordPress, WP-CLI. I quickly discovered that for someone who prefers the keyboard to the mouse, it’s a wonderfully powerful, quick, and robust tool for managing and updating WordPress sites.
What follows below is a resource that I’ve building up for myself. When and where I find documentation and links that I use for growing my knowledge about how to harness the power of WP-CLI, I post them here. Feel free to bookmark this page in your own browser if find it of value.
Commands and Resources for WordPress Generally
Commands for Gravity Forms
- WP-CLI add-on for Gravity Forms on the WordPress plugin repo
- Documentation from Rocket Genius for the WP-CLI add-on
My Own Personal Favorites for WP-CLI
Duplicate a Page or Post from Existing Page or Post
wp post create --from-post=136 --post_type=page --post_parent=41 --post_title="Insert New Page Title Here" --post_status=publish
Change a User’s Password
wp user update username --user_pass=insert-new-password
Delete a User
# Delete user 123 and reassign posts to user 567 $ wp user delete 123 --reassign=567 Success: Removed user 123 from http://example.com
This is very useful when upping a database after installing an SSL certificate or updating A-records on a new website.
wp search-replace 'http://example.com' 'http://example.test' --recurse-objects --skip-columns=guid --skip-tables=wp_users
wp search-replace --all-tables 'http://example.com' 'https://example.com' --log --dry-run
Bulk Delete Gravity Form Entries
This bit of functionality requires the Gravity Forms CLI Add-On to be installed on the site, but once it’s there, it’s a lightning fast way to bulk delete spammy form submissions.
wp gf entry delete $( wp gf entry list 1 --status=active --format=ids ) --force
List Only Those Plugins with an Available Update
Rather than listing the entire list of plugins running on a WordPress site, it can be helpful to see only those in need of an update.
wp plugin list --update=available
Check and Change the Admin Email Address
Before changing the current admin email address, it is a very good idea to double-check what it is. To do so, use the following command to search the Options table to the correct entry.
wp option list --search="admin_email"
Once we have confirmed that the current admin email address does need to be changed, we can do so easily with the following command.
wp option update admin_email firstname.lastname@example.org
A Lightning Talk at the Philly ‘burbs WordPress Meetup
View Dipping into wp-cli on Notist.
In early December 2019, I shared a few quick items that I’d already learned about WP-CLI. I gave a lightning talk at the Philly ‘burbs WordPress Meetup’s 12 Tips of WordPress. The slides embedded above are from that little talk.
Guide to WP-CLI Command Structure
In June 2022, the smart people at Delicious Brains shared their blog post about the WP-CLI command structure. It’s a great resource for understanding (or reminding yourself) how to format WP-CLI commands.
Blog post: Our Guide to WP-CLI Command Structure
Last updated: 01-Jul-2022