For determining whether user is a super user, we do something like this :

$user = JFactory::getUser();
$isAdmin = $user->get('isRoot');
if ($isAdmin) {
echo 'You are an Administrator';

What would be the best way to know that the logged in user belongs to a specific usergroup or has some specific viewing access level?

1 Answer 1


To get an array of groups the currently logged in user belong to, you can use the following:

$user   = JFactory::getUser();
$groups = JAccess::getGroupsByUser($user->id);


To get the names of these groups, you can run a database query (add after the code above)

$user   = JFactory::getUser();
$groups = JAccess::getGroupsByUser($user->id);
$groups_list = '(' . implode(',', $groups) . ')';

$db = JFactory::getDbo();
$query = $db->getQuery(true)
    ->where($db->qn('id') . ' IN ' . $groups_list);
$rows = $db->loadObjectList();


To get the user's access levels, you can use the following:

$user   = JFactory::getUser();
$levels = JAccess::getAuthorisedViewLevels($user->id);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.