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!
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 section of the and to get an overview of basic features and terms of the application.
In WordPress, a User Role is a combination of:
By default, WordPress has the fundamental 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.
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.
You may check or list the existing user and user role with the following command:
wp user list
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>
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>
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>
Adds, removes, and lists capabilities of a user role.
wp cap <command>
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
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.
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.
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 WordPress, including 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.
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.
Our award-winning customer care team is here for you.Contact Support