How to Manage WordPress Roles? (Easily Way)

Managing WordPress roles and editing them is easy with WordPress.

Furkan Zerman
Stingy Developer
2 min readJul 17, 2021

--

Photo by FLY:D on Unsplash

WordPress roles are major authentication and user management system in WordPress. Editing and customizing them is necessary for some website types such as e-commerce, LMS. Therefore, some tools should be in WordPress. In this article, we deep to WordPress’ core.

Getting Roles

By using this function, you can get editable roles with the capabilities that they include.

Adding Roles

If you want to create a new role in WordPress, you can use this pattern by writing in functions.php. You can get the parameters of add_role() the function below.

  1. The slug of the role
  2. The name of the role
  3. The array of the capabilities

Remove Roles

If you want to remove a role, you can use remove_role(role_name) function.

Edit Existing Roles

You can edit(add/remove) capacibilties of the roles by using add_cap and remove_cap functions.

Checking Capacibilities of Users

If you want to check capacibilities of a certain user, you can use user_can($user, $capacibilty). Also, you can check capacibilities of current user (the loginned user), by using current_user_can($capacibilty) function.

Conclusion

In this article, I explained;

  • How to get roles?
  • How to add a role?
  • How to remove roles?
  • How to edit a role?
  • How to check capacibilities of users?

I hope, you can learn how to manage roles in WordPress. See you in next articles.

Happy coding with Stingy Developer.

--

--