View all the user roles and permissions configured in your WordPress website

Display all user roles in a WordPress application

Do you want to see the user roles and permissions configured in your WordPress website? WordPress comes with multiple user roles and permissions. These roles define what a user can do and what’s not. These roles are also important to managing website security.

In this article, we will see how to view all the user roles and permissions configured in your WordPress and WooCommerce website.

At first, we will fetch all user roles using WordPress’s built-in function get_editable_roles().
This function returns all roles and then we can fetch the details of each user role.

How to programmatically get user roles and permissions

To get the WordPress roles and permissions programmatically, execute the following code:

// get user roles
$editable_roles = get_editable_roles();

// iterate through each role and get the details
foreach ($editable_roles as $role => $details) {
    $sub['role'] = esc_attr($role);
    $sub['name'] = translate_user_role($details['name']);
    $roles[] = $sub;
}

// print details of each role
echo '<pre>';
   print_r( $roles ); // Should return an array of enabled user roles
echo '</pre>';

Default roles and permissions

To view default WordPress roles, navigate to the admin panel and then click on users.

wordpress-user-roles
WordPress users module in admin panel

A fresh WordPress copy has the following six user roles:

  • Super admin
  • Administrator
  • Editor
  • Author
  • Contributor
  • Subscriber

Super admin

The super admin role manages when we have a network administered multiple WordPress websites.

Administrator

The admin role manages the full roles of a single WordPress website.

Editor

The editor role can publish and manage posts including the posts of other users.

Author

Authors role can publish and manage their own posts.

Contributor

The contributor can write and manage their own posts but cannot publish them.

Subscriber

The subscriber can only manage their profile.

Related Posts