Check if a user has a role in Drupal 7

Checking if a user has a role in Drupal 7

// Load the currently logged in user.
global $user;
// Check if the user has the 'editor' role.
if (in_array('moderator', $user->roles)) {
// do your stuff
}

 

Editorial Staff
 

Editorial Staff at tutsplanet is a dedicated team to write various tutorial articles.