1 user.module user_role_has_permission($role_name, $permission_name)

Checks if a user role has a permission.

@since 1.26.0 Function added


string $role_name: The role machine name.

string $permission_name: The permission to check.

Return value

bool: TRUE if the role has the permission, FALSE if it does not have the permission.


core/modules/user/user.module, line 472
Enables the user registration and login system.


function user_role_has_permission($role_name, $permission_name) {
  $role = user_role_load($role_name);
  return $role ? in_array($permission_name, $role->permissions) : FALSE;