How to Use WP-CLI – Common WordPress Management Tasks
On this page
- Contents
- Before You Begin
- Plugin Management
- List Installed Plugins
- Install and Activate a Plugin
- Install Multiple Plugins at Once
- Activate a Plugin
- Deactivate a Plugin
- Delete a Plugin
- List Active Plugins with Available Updates
- Update a Plugin
- WordPress Configuration Management
- Check the Current Website URL
- Change the Website URL
- Working with the Database
- Export the Database
- Import a Database
- User Management
- List All Users
- List Users by Role
- Create a New User
- Delete a User and Reassign Content
- Change a User Password
- Change a User Email Address
- Change a User Role
- WordPress Core Verification
- Why Use WP-CLI?
- Summary
WP-CLI is a command-line tool that allows you to manage WordPress directly from an SSH terminal without logging in to the WordPress administration panel. It is particularly useful for bulk operations, troubleshooting, automation, and server-side management tasks.
Using WP-CLI, you can:
- Manage plugins and themes
- Create, modify, and delete users
- Export and import databases
- Update WordPress settings
- Verify core files
- Automate administrative tasks
Contents
- Before You Begin
- Plugin Management
- WordPress Configuration Management
- User Management
- Working with the Database
- WordPress Core Verification
Before You Begin
To use WP-CLI, you must first have SSH access enabled for your hosting account.
After connecting to your account via SSH, navigate to the root directory of your WordPress installation.
Example:
cd yourdomain.com/
cd public_html/
You should now be in the main WordPress directory and ready to execute WP-CLI commands.
Plugin Management
List Installed Plugins
To display all installed plugins:
wp plugin list
The output includes:
- Plugin name
- Status (active/inactive)
- Available updates
- Installed version
Install and Activate a Plugin
Example:
wp plugin install jetpack --activate
This command downloads, installs, and activates the plugin automatically.
Install Multiple Plugins at Once
wp plugin install really-simple-ssl jetpack ninja-forms --activate
Activate a Plugin
wp plugin activate hello
Deactivate a Plugin
wp plugin deactivate hello
Delete a Plugin
wp plugin delete hello
List Active Plugins with Available Updates
wp plugin list --field=name --status=active --update=available
Update a Plugin
wp plugin update plugin-name
Example:
wp plugin update duplicator
WP-CLI will download and install the latest available version automatically.
WordPress Configuration Management
Check the Current Website URL
wp option get siteurl
This command displays the URL currently configured in WordPress.
Change the Website URL
wp option update siteurl https://new-domain.com
This is useful after migrating a website to a new domain.
Note: This changes the WordPress configuration only. It does not modify your hosting or DNS settings.
Working with the Database
Export the Database
To create a database backup:
wp db export
WP-CLI generates an SQL file containing a copy of the current database.
Import a Database
To restore a database from an SQL file:
wp db import backup-file.sql
This command imports the specified database backup into the current WordPress installation.
User Management
List All Users
wp user list
The output includes:
- User ID
- Username
- Display name
- Email address
- Registration date
- User role
List Users by Role
Example:
wp user list --role=administrator
Available WordPress roles include:
- administrator
- editor
- author
- contributor
- subscriber
Create a New User
Example:
wp user create john john@example.com --role=administrator
WP-CLI will generate a password automatically and display it after creation.
Delete a User and Reassign Content
wp user delete john --reassign=jane
All content created by the deleted user will be assigned to the specified account.
Change a User Password
First, identify the user ID:
wp user list
Then update the password:
wp user update 1 --user_pass=NewPassword123
Change a User Email Address
wp user update 1 --user_email=newemail@example.com
Change a User Role
Example:
wp user set-role 1 administrator
This command updates the user’s permissions.
WordPress Core Verification
One of the most useful WP-CLI features is the ability to verify WordPress core files against the official WordPress checksums.
Run:
wp core verify-checksums
This command checks whether any WordPress core files have been modified.
It can help identify:
- Corrupted files
- Unauthorized modifications
- Potential malware infections
Important: Checksum verification does not replace a full malware scan, but it can indicate that WordPress core files have been altered unexpectedly.
Why Use WP-CLI?
WP-CLI is particularly useful when:
- You cannot access the WordPress admin panel.
- You need to perform bulk operations.
- You are managing multiple WordPress websites.
- You want to automate repetitive tasks.
- You need to troubleshoot WordPress from the server level.
Summary
WP-CLI is a powerful command-line tool for managing WordPress through SSH. It allows you to install and update plugins, manage users, modify WordPress settings, create database backups, restore databases, and verify the integrity of WordPress core files—all without logging in to the WordPress dashboard.
Didn't find an answer?
Our support team is here for you 24/7 – write to us and we will help you sort it out.