WP CLI allows managing WordPress admin actions through the command line. Most of the actions we take from the admin area, especially tricky things, can be handled quickly via WP CLI.
Installing WP CLI
If you’re on a managed host, chances are high that it’s pre-installed. Run the below command from the terminal to check if WP CLI is installed.
If WP CLI is installed, this will output the WP CLI version at the end. This article explains how to install WP CLI on various platforms The Complete Guide to Installing WP-CLI
Download or reinstall the WP core
wp core download
This will download the latest WordPress core zip from wp.org and extract it to the current folder.
--forcewill override the existing installation. If WP is installed on the same directory,
wp core downloadwill fail. That’s where the force flag is used.
--skip-contentThis flag is used to skip the wp-content folder while downloading core files. So default themes and plugins bundled with WordPress will be skipped.
--versionThe latest WordPress version gets installed if the version flag is not specified.
Whenever I need to reinstall WordPress core files, I do the following:
- Check if core files are modified with
wp core verify-checksums.
- If checksums don’t match, I check the currently installed version number with
wp core version, this is to avoid accidental core version updates.
- Make sure the present working directory is public_html or web root. This is important. If we run wp core download from somewhere else, like 📁 wp-content/plugins folder, core files will be downloaded there, which doesn’t make sense.
- Then, download the core with
wp core download --skip-content --force --version=[NUMBER]
Install Plugins and themes
wp plugin install woocommerce wp theme install astra #To delete a plugin or theme wp plugin delete woocommerce wp theme delete astra #To deactivate a plugin or theme wp plugin deactivate woocommerce wp theme deactivate astra
--forceis used to reinstall.
--skip-themesare used to skip the theme and plugin initialization. This avoids fatal errors from a theme or plugin preventing installation.
--activatewill activate the plugin/theme after installation.
--versionto specify the version number.
I usually do that when I need to reinstall the latest version of a plugin or theme:
wp plugin install woocommerce --force --skip-plugins --skip-themes wp theme install astra --force --skip-plugins --skip-themes
Reset user password
Sometimes the reset password email never reaches the inbox for various reasons. User password can be changed with WP CLI
wp user update 123 --user-pass=newpass
123 is the user ID. Inseated of user ID, we can use user email or username. To get this info we can list the users with
wp user list