Nexcess Logo

Update User Roles in WordPress Using WP-CLI

Knowledge Base Home

Notice anything different?

We've enhanced the appearance of our portal and we're working on updating screenshots. Things might look different, but the functionality remains the same.
January 27, 2022

Optimally manage your user roles and the capabilities allowed per role for your WordPress site! No need for a web browser, using the WP-CLI is quite handy!

User Roles and Capabilities in WordPress

You may refer to the Managed WordPress Hosting page to get an idea of our plans. 

WordPress User Roles and Capabilities allow you to control what other users can or cannot do on your site. You can use them to manage user actions such as writing and editing posts, creating new pages, moderating comments, installing plugins, adding new users, and much more.

WordPress User Roles and Capabilities give you the ability to control what other users can or cannot do on your site. You can use them to manage user actions such as writing and editing posts, creating new pages, moderating comments, installing plugins, adding new users, and much more.

This article will teach you how you can manage user roles using the WordPress Command Line Interface (WP-CLI). Managing User Roles using WP-CLI is super easy and handy. The best part is that you do not need a web browser to operate WP-CLI. 

WP-CLI is pre-installed on all the servers deployed on servers. The below mentioned steps demonstrate how you can leverage WP-CLI to manage users, especially update user roles. You may also have a look at the WordPress section of the Nexcess Knowledge Base and WordPress Glossary: WordPress Terms New WordPress Users Need To Know to get an overview of basic features and terms of the application. 

Managing User Roles in WordPress

In WordPress, a User Role is a combination of:

  1. Role: A role is the name of a user group that will be displayed in your WordPress Admin Panel.

  2. Capabilities: Capabilities are the privileges that admins can enable or disable.

By default, WordPress has the fundamental User Roles:

  • Super Admin: This profile has access to the entire website, including network administrative features.

  • Administrator: The profile(s) that has all administrative privileges.

  • Editor: The profile(s) that can create, edit, publish theirs, and other users’ posts.

  • Author: The profile(s) that can create, edit, and publish their posts only.

  • Contributor: The profile(s) that can create and edit their posts but not publish them.

  • Subscriber: The profile(s) that can only manage their own profiles.

Purpose of WordPress User Roles

If you are using the WordPress application as a single user, then you might not have thought about the rich functionality in WordPress for administering users and roles. If you have a team who looks after your WordPress site or you want to give specific responsibilities to someone, you might need to consider, reading further as WordPress users and roles feature will enable you to decide the domain of various users and restrict their access to their needs, including the ability to post, install or uninstall any plugin.

Managing Users and Roles Using WP-CLI 

It would be best if you connected to your server remotely via SSH to use WP-CLI. Please refer to the Locating your SSH credentials in managed WordPress and managed WooCommerce hosting article for more information. 

Access your domain root directory, where your wp-config.php file is located, else WP-CLI will not work. Normally the location would be /home/username/

The sections below explain how to update a user role using WP-CLI

Listing Users

You may check or list the existing user and user role with the following command:

wp user list

Creating a New User

The following command will help you create a new user_login (username), email address, role, and password (which will be auto-generated):

wp user create <user_login> <user-email> --role=<role>

If you want to create a user with a defined username, email address, role, and custom password, then the command will be as follows:

wp user create <user_login> <user-email> --role=<role> --user_pass=<password>

Updating a User

The commands used to update an existing user are as follow:

wp user update <parameter>

For example, if you would like to update display_name, and user_pass (password), then the following command will be helpful:

wp user update <ID> --display_name=<display_name> --user_pass=<password>

Deleting a User

The below-mentioned command may help you to delete the user. For example, the command lets you delete the user and reassign that user’s posts to any other user:

wp user delete <user-id> --reassign=<user-id>

Capabilities for Users Roles

The capabilities of administrators differ between a Single Site Installation and Multisite WordPress Installation. The How to configure a WordPress multisite network article covers well the information related to a Multisite WordPress Installation.

Understanding the Basic Actions

Let's have a look at the set of commands related to managing capabilities

Adds, removes, and lists capabilities of a user role.
wp cap <command>

Adding a Specific Capability to a Role

To add a specific capability to a role: 

wp cap add <role> <capability>

For example, to add 'spectate' capability to 'author' role:

$ wp cap add author spectate

Listing the Capabilities

To list the capabilities: 

wp cap list

For example, to add all caps from 'editor' role to 'author' role:

$ wp cap list 'editor' | xargs wp cap add 'author'
Success: Added 24 capabilities to 'author' role.

Removing Capabilities from a List

You can remove the capabilities from the list.

For example, to remove all capabilities from 'editor' role that also appear in 'author' role.

$ wp cap list 'author' | xargs wp cap remove 'editor'
Success: Removed 34 capabilities from 'editor' role.

Useful WordPress Links for Developers & Admins

Next Steps?

Read more about the Fully Managed WordPress Hosting and its benefits for your business.

Build Better Websites with Fully Managed WordPress Hosting 

It’s hosting optimized for WordPress. That means a faster, more secure and scalable website. Smart monitoring tools are built-in to help you keep it that way. 

It’s why WordPress Users Trust Nexcess Hosting.

We also have a variety of Nexcess support articles about WordPressincluding how to get your site going with a number of different configuration options. These resources include a great article on setting this up for Migrating to Nexcess with managed WordPress and managed WooCommerce hosting

24-Hour Assistance

If you need any assistance with the above-mentioned, don't hesitate to reach out. For 24-hour assistance any day of the year, Nexcess customers can contact our support team by email or through your Client Portal.

Useful YouTube > Nexcess Channel Links

Resources for More Information

Need more help? The Applications, WooCommerceand WordPress sections within the Nexcess Knowledge Base are important resources for those seeking additional knowledge. Or, check out our related articles below.

New Customers: Fully Managed Hosting Solutions

Not a Nexcess customer yet? Check out our fully managed hosting solutions. The option to chat with an expert is also available.

Related Articles

Christy Joy
Christy Joy

Christy Joy has over five years of professional experience as a Senior Server & System Administrator and has enjoyed working with technology platforms at scale her entire career.

Her hobbies and interests include blogging focused on her ample technology insights gained over an accomplished career, traveling, making new friends, listening to music, artistic works, and social networking. To fly high without any limitations is the dream, Christy reminds us all.

We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.