Skip to content

WP-CLI COOKBOOK

  • by

WP-CLI is a command-line tool that lets you accomplish a wide array of WordPress development tasks from within the command line. This means no breaking focus and less wasted time.

This list assumes that you have a basic understanding of SSH and running commands in a terminal/shell. It is ALWAYS recommended to make a backup of your site’s files and database before running any of these commands.

Below is a list that I have comprised of some of the WP-CLI commands that I use the most during day-to-day support operations:

WP Core

Core Download:

wp core download --force

Core Download with Version Flag:

wp core download --force --version=

Generate WP Config:

wp config create --dbname=testing --dbuser=wp --dbpass=securepswd

Themes and Plugins

Force Re-install ALL Plugins:

wp plugin install $(wp plugin list --field=name) --force

Force Re-install ALL themes:

wp theme install $(wp theme list --field=name) --force

Force Re-install specific list of plugins/themes:

wp plugin install --force plugin1 plugin2 --skip-plugins --skip-themes && wp theme install --force theme1 theme2 --skip-plugins --skip-themes

Database Manipulation

Check Database Size

wp db size --human-readable --skip-themes --skip-plugins

Export Full Database:

wp db export

Export WooCommerce Orders

wp export --post__in=$(wp eval 'foreach( get_posts(array("post_type" => "shop_order", "posts_per_page" => -1, "fields" => "ids")) as $id ) { echo $id. ","; }') --max_file_size=200

Delete All WooCommerce Orders

wp post delete $(wp post list --field=ID --post_type="shop_order") --force

Delete WooCommerce Customers

wp user delete $(wp user list --role=customer --field=ID) --reassign=2

Delete Transients

wp transient delete --all

Update WordPress Database

wp core update-db

Enumeration

Get Post Info By Post ID

wp post get post-id-number

Administration

Delete User:

wp user delete <id>

Add Admin User:

wp user create user-name [email protected] --role=administrator

Change/Update Password:

List users to view the user ID

wp user update id --user_pass=password 

Force Password Reset

Without Email:

wp user reset-password --skip-email

With Email:

 wp user reset-password <user-id>

Set User Role:

wp user set-role 12 administrator

User Roles:

administrator
contributor
author

Reset All User Roles to Default

wp role reset --all

Delete Spam Comments:

wp comment delete $(wp comment list --status=spam --format=ids)

Delete All Comments:

wp comment delete $(wp comment list --status=hold --format=ids)

Shuffle Salts

wp config shuffle-salts

Multisite

Get Site List:

wp site list

Get Site URL:

wp option get siteurl

List Super Admins:

wp super-admin list

List ALL users in Multisite:

wp user list --network

Assign Super Admin Role:

wp user set-role [user-ID] super-admin

Leave a Reply

Your email address will not be published. Required fields are marked *