Hi

I have implemented a form_alter function in my template.php but I only want the changes to apply if the user is NOT the admin user. Would anyone be so kind as to show me how to test a global variable to see if the admin user is logged on ?

Thanks

Dave

Comments

mittalpatel’s picture

As admin user will always have user id 1. We check that the current logged in user has user id 1 or not. If not than you can execute your code.

	global $user;
	if($user->uid != 1)
	{
		//Execute your code here
	}

This will solve your issue.

flk’s picture

By admin do you mean, the logged in person is not user 1 or do you have roles?

//load the current users details
global $user;

//check users roles
//if user is not a given role or not superadmin (uid 1)
if(!$user->roles[4] || $user->uid !=1) {
  //do something here
}


El Bandito’s picture

As usual the Drupal community delivers. Works perfectly.

Cheers

Dave