To check if the user is an admin in drupal

0
Your rating: None

It is always possible to check if the user is logged in as admin using the drupal built in user_access() function, super administrator account doesn't have a role by default so you can check it using :

<?php
if(user_access('administer')) 
{....your code goes here....}
?>

However, in case if you want to check whether the logged-in user has a certain role. For example, something like this if you have a role called 'moderator'

<?php
global $user;
if(is_array($user->roles) && in_array('moderator', $user->roles))

{... your code goes here ...}

?>
 #

in_array('moderator', array_values($user->roles))

 

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India