How to Use WP-CLI – Common WordPress Management Tasks

On this page
  1. Contents
  2. Before You Begin
  3. Plugin Management
  4. List Installed Plugins
  5. Install and Activate a Plugin
  6. Install Multiple Plugins at Once
  7. Activate a Plugin
  8. Deactivate a Plugin
  9. Delete a Plugin
  10. List Active Plugins with Available Updates
  11. Update a Plugin
  12. WordPress Configuration Management
  13. Check the Current Website URL
  14. Change the Website URL
  15. Working with the Database
  16. Export the Database
  17. Import a Database
  18. User Management
  19. List All Users
  20. List Users by Role
  21. Create a New User
  22. Delete a User and Reassign Content
  23. Change a User Password
  24. Change a User Email Address
  25. Change a User Role
  26. WordPress Core Verification
  27. Why Use WP-CLI?
  28. 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

  1. Before You Begin
  2. Plugin Management
  3. WordPress Configuration Management
  4. User Management
  5. Working with the Database
  6. 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.