Showing posts with label user. Show all posts
Showing posts with label user. Show all posts

Friday, February 6, 2009

How to find what roles user has in Drupal

User object in Drupal has a roles array and all you have to do is to check if this array has the role you want.

Here is an example:

<?php
global $user;
$user->roles[ "ROLE_ID" ] = "ROLE_NAME";

// You can traverse through the array
// and check if user has the role you want
foreach($user->roles as $rid => $role){
if($role == "role_i_want"){
// Do something
}
}
?>