Manage WordPress Users Using WP-CLI

InMotion Hosting’s WordPress Hosting includes WP-CLI pre-installed. WP-CLI, is a compilation of tools and commands that allow you to easily maintain your WordPress website(s) right from the command line. The user command allows you to maintain the database of users for your website. With it, you can create, view, edit, and delete users. In this guide, you will learn how to use WP-CLI’s user command to manage your WordPress users.

Add a User

Using the wp user command, you can create a user to add to your WordPress website. The steps below will guide you through the process of adding a user (with administrator privileges) from the command line.

  1. SSH into your server as the cPanel user that owns the website.
  2. Use the cd command to switch into the document root directory of your website.Example: cd public_html/my_website
  3. Run the following command:wp user create $username $emailaddress –role=$roleBe sure to replace the ($username and $emailaddress) example values with your own custom values and ($role) the role you would like the user to be configured with. When the command completes running, a password will be returned, as in the example output below:

    [email protected] [~/public_html]# wp user create exampl3 [email protected] –role=administrator
    Success: Created user 2.
    Password: srWCdc3c*(&b

    Refer to the table below, to determine what each role’s capabilities are. This will help you to choose which role to set as the user in the command above.

    RoleDescription
    Super AdminCan access all administration features (including site network administration).
    AdmnistratorCan access all administration features (within a single site).
    EditorCan publish and manage posts (including posts by other users).
    AuthorCan publish and manage their own posts.
    ContributorCan write and manage their own posts (but cannot publish).
    SubscriberCan only manage their profile.

List Users

The wp user command can also be used to list the users currently in the database. The steps below describe how to list users of your WordPress site with WP-CLI.

  1. SSH into your server as the cPanel user that owns the website.
  2. Use the cd command to switch into the document root directory of your website.Example: cd public_html/my_website
  3. Run the following command:wp user listThis command’s output will display the full details of all users.
    [email protected] [~/public_html]# wp user list +----+----------+------------+--------------------+---------------------+-------+ | ID |user_login|display_name| user_email         | user_registered     | roles | +----+----------+------------+--------------------+---------------------+-------+ | 1  | admin    | admin      | [email protected]  | 2017-12-16 00:57:44 | admin | | 2  | exampl3  | exampl3    | [email protected] | 2017-12-18 20:15:53 | admin | +----+----------+------------+--------------------+---------------------+-------+

Edit a User

The wp user command can also be used to modify the details stored for a user. The steps below will guide you through changing a user’s email address using WP-CLI.

  1. SSH into your server as the cPanel user that owns the website.
  2. Use the cd command to switch into the document root directory of your website.Example: cd public_html/my_website
  3. Run the following command:wp user update $user$field=$valueBe sure to replace the ($user and $value) example values with your own custom values and ($field) the field you would like the user to be modified with. When the command completes running you should see a successful message, as in the example output below:
    [email protected] [~/public_html]# wp user update exampl3 [email protected] 
    Success: Updated user 2.

Delete a User

To delete a user, you can use the wp user command. The instructions below will guide you through the process of deleting a WordPress user using WP-CLI.

  1. SSH into your server as the cPanel user that owns the website.
  2. Use the cd command to switch into the document root directory of your website.Example: cd public_html/my_website
  3. Run the following command:

    wp user delete $user –reassign=$username

    Be sure to replace the ($user and $username) example values with your own custom values. When the command completes running you should see a successful message, as in the example output below:

    [email protected] [~/public_html]# wp user delete exampl3 --reassign=admin Success: Removed user 2 from https://example.com.

Congratulations! Now, you know how to manage your WordPress users from the command line, using WP-CLI. To learn more about WP-CLI, be sure to check out our WP-CLI Education Channel.

IC
InMotion Hosting Contributor Content Writer II

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+