How to check is an user in admin group?

If you need to check user on certain kind of Joomla ACL group membership:

isadminiJoomla 2.5.x and Joomla 3.x :

Simple check logged user is Super Admin or not

    
	function isUserSuperAdmin()
	{
		  $user = JFactory::getUser();
		  return $user->get('isRoot');
	}    
    
	
	if (isUserSuperAdmin()) 
	{
	  //your code for Super Administrators...
    }
Simple check logged user is in Administrator groups

	function userIsInAdminGroups($uid = 0)
	{
	   $in_admin_group = false;
	   $usergroup = JAccess::getGroupsByUser($uid);
	   $admin_groups_ids = array(7,8); // 7- it default id of Adminis group, 8 - dafault id of Super Admins group
		  foreach ($admin_groups_ids => $agid)
		  {
			  if (in_array($agid,$usergroups)) $in_admin_group = true;
		  }	  
		  return $in_admin_group;	
	}
	
	  if (userIsInAdminGroups(JFactory::getUser()->id))
	  {
		  //your code for users in administrator groups...
	  }
	

old Joomla 1.5.x :


	  function checkUserInAdminGroups( $usertype='' )
	  {
		$admin_groups = array("Super Administrator","Administrator");		
		return (in_array($usertype,$admin_groups));
	}
	
	if (checkUserInAdminGroups( JFactory::getUser()->usertype))
	{
		//your code for users in administrator groups...
	}

Also you can add managers in checking

$admin_groups = array("Super Administrator","Administrator","Manager");	
Scroll to Top
Ads: