i'm wondering why there is no function like get_role_by_name()

when you add a role in drupal, you define a name, not a $id => $name, so the name should be used to identify a role

my goal is to use user_has_role() with the name of the role i want to check for, i don't want to look up the $rid for the role name or even hardcode it

Comments

ibot’s picture

I'm using this piece of code to check if the current user has the given roles:

function user_has_role ( $roles )
{
  global $user;
  $check = array_intersect($roles, array_values($user->roles));
  return empty($check) ? FALSE : TRUE;
}

If it makes sence i could submit a patch...

Thanks for your work on the module.