Joomla Check If User Exists In Group

This tutorial will check if the user exists in a group in Joomla and return true.

We must first get the user object for the currently logged in user.

    //get logged in user
    $user = JFactory::getUser();  

Now that we have the user object we can check to see if they belong to the group that we require

    $group_id = 3;//This is the group we are checking. You can get this from the group backend in the admin

    

    if(in_array($group_id, $user->getAuthorisedGroups()))

    {

    	//The user is in this group

        echo 'Found! The user belongs to this group';

    }else{

    	echo 'The user does not belong to this group';

    }

As you can see, it is really easy to check if the user belongs to a group in Joomla. Leave a comment 🙂

Please Post Your Comments & Reviews

Welcome to Western Studios

We provide professional website and mobile softwares including Joomla, Wordpress and more.