Drupal has two benefit functions:
1. user_is_anonymous
2. user_is_logged_in

Drupal 7 has merge module adminrole to core. I think Drupal should have function to check if user is admin role or not.

I suggest this code merge to core.

function user_is_admin() {
  global $user;
  if($user->uid == 1) {
    return TRUE;
  }
  $rid = variable_get('user_admin_role');
  if (isset($rid)) {    
    return isset($user->roles[$rid]);
  }
}

Therefore, Drupal has three benefit functions:
1. user_is_anonymous
2. user_is_logged_in
3. user_is_admin

Comments

ijortengab’s picture

Issue summary: View changes
ankitadmane’s picture

Assigned: Unassigned » ankitadmane

It is also possible to check so using the drupal built in user_access() function, for example the super administrator account doesn't have a role by default so you can check it using :

if(user_access('administer')) {... do something ...}

hope it might help somebody.

dcam’s picture

Version: 7.x-dev » 8.0.x-dev
Assigned: ankitadmane » Unassigned

New features must be added to the current development version first, which is Drupal 8.

I can't imagine that this will ever be added, however, because the admin role is not guaranteed to be available. It's created by the standard installation profile. It may not be installed or it might even get deleted by some admins. I'll let someone higher up decide whether or not to close this issue though.

ijortengab’s picture

Status: Active » Closed (won't fix)

Closed wont fix, in favor of user_access('administer site configuratoin');

wombatbuddy’s picture

Drupal 9

\Drupal::currentUser()->hasPermission('administer site configuration');

$user = \Drupal::entityTypeManager()->getStorage('user')->load(3);
$user->hasPermission('administer site configuration');