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=$role

    Be 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.

    Role Description
    Super Admin Can access all administration features (including site network administration).
    Admnistrator Can access all administration features (within a single site).
    Editor Can publish and manage posts (including posts by other users).
    Author Can publish and manage their own posts.
    Contributor Can write and manage their own posts (but cannot publish).
    Subscriber Can 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 list

    This 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    | admin1[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=$value

    Be 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.

JB
John-Paul Briones Content Writer II

John-Paul is an Electronics Engineer that spent most of his career in IT. He has been a Technical Writer for InMotion since 2013.

More Articles by John-Paul

Was this article helpful? Let us know!