How to manage users and their roles via WP-CLI?

Updated on January 12, 2022

WP-CLI is a combination of tools and commands that permit you to manage your WordPress website straight from the command line. The main advantage of using WP-CLI is that it does not require any web browser to operate. 

With the help of WP-CLI, you can efficiently perform any general administration tasks, maintain your existing website, manage WordPress users, or make changes in the database; WP-CLI is the best option to perform these tasks. 

In this article, we briefly explain how you can manage WordPress users with the help of WP-CLI. 

First, you must connect your server via SSH or SFTP using Master User or Application User. 

Note: You can see the instructions on how to connect your application via SSH and SFTP from our knowledge base article.

After connecting SSH, go to cd applications/application_folder_name/public_html/

WP-CLI permits you to perform multiple tasks related to WordPress users.

If you write wp user and press Enter, WP-CLI will offer the arguments accepted for this command:

How To Manage Users And Their Roles Via WP CLI?
  • To List Existing Users:

To view the list of all existing WordPress users, enter the command.

wp user list

The output after the execution of the command mentioned above looks like this:

This information includes the user name from which you can log in to the WordPress site dashboard, the name displayed on their post, user email address, the date on which the user registered, and the role assigned to that particular user.

  • To Create a New User:

To create a new administrator user, replace NEWUSERNAME and EMAILADDRESS with your information

wp user create NEWUSERNAME EMAILADDRESS --role=administrator

After executing the command mentioned above, a new administrator user will be created with an auto-generated password similar to the following.

new administrator user will be created with an auto-generated password

You can also set the user password using the below-mentioned command by replacing the “NEWPASSWORD” with your password.

wp user create NEWUSERNAME EMAILADDRESS --role=administrator --user_pass=NEWPASSWORD
  • To Change a User’s Password:

You can change your user password using the below-mentioned command by replacing the “MYNEWPASSWORD” with your new password.

wp user update USERNAME --user_pass=MyNewPassword
  • Remove a User:

If you want to remove any particular user, you can replace “USERNAME” with the actual user you want to remove.

wp user delete USERNAME

After executing the command mentioned above, the system-generated prompt will appear for the confirmation to delete a user—Press “y” to proceed.

  • To Change a User’s Role:

Different WordPress users can be assigned different roles, and each role has different access. Following are the roles of users:

  1. administrator,
  2. editor,
  3. author,
  4. contributor, and
  5. subscriber.

To assign a role to any user, you can use the below mention command by replacing USERNAME and ROLE with the appropriate required terms:

wp user update USERNAME --role=ROLE

For instance:

wp user update new user --role=editor


Does this article helped you with the configuration of user roles? If there’s anything that still needs to be discussed, you can always visit our live chat and share your product-related issues with us! We are always here to assist.

Need More Help!

Type in your question at the knowledge base website or comment below

Leave a Comment

Your email address will not be published. Required fields are marked *