Table of contents
Get the industry’s fastest hosting for WordPress◦ 99.999% uptime
◦ Comprehensive security
◦ 24/7 support

WordPress GuideWP-CLI → User Roles

Update user roles in WordPress using WP-CLI

Office workers comparing WordPress hosting providers

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!

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

User roles and capabilities in WordPress

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.

Managing user roles in WordPress

In WordPress, a User Role is a combination of:

By default, WordPress has the fundamental User Roles:

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.

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/domain.com/html.

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:

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):

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

Updating a user

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

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

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:

Capabilities for users roles

The capabilities of administrators differ between a Single Site Installation and Multisite WordPress Installation.

Understanding the basic actions

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

wp cap <command>

Adding a specific capability to a role

To add a specific capability to a role: 

For example, to add ‘spectate’ capability to ‘author’ role:

Listing the capabilities

To list the capabilities:

wp cap list

For example, to add all caps from ‘editor’ role 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.

Additional resources

What is WordPress? →

A complete beginner’s guide—from use cases, to basics, to how to get started

8 WP-CLI commands to clean up and optimize your Site →

Want to clean up your WordPress site without having to add multiple plugins? By using WP-CLI, you can run many useful commands to helpfully clean up your database and elements related to your site. In this post, many of the most common tasks are covered.

How to integrate WordPress and Slack →

If your org uses Slack and WordPress, there are several ways you can tie them together.

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. To fly high without any limitations is the dream, Christy reminds us all.