◦ Comprehensive security
◦ 24/7 support
WordPress Guide → WP-CLI → User Roles
Update user roles in WordPress using WP-CLI
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 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.
Managing user roles in WordPress
In WordPress, a User Role is a combination of:
- Role: A role is the name of a user group that will be displayed in your WordPress Admin Panel.
- 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.
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:
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.
wp user delete <user-id> --reassign=<user-id>
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.
Getting started with updating user roles in WordPress
When you’re ready to upgrade your WordPress hosting, Liquid Web can help. We’ve been offering the premium hosting for WordPress sites for decades—with the fastest speeds, best uptime guarantees, and most robust security features. Click below to explore options or start a chat to connect with one of our WordPress hosting experts right now.
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.