• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Check for usergroup?

#1
So how do I check to see if a person is in a group for accesing a page?

Like this:
Code:
$visitor = XenForo_Visitor::getInstance();
        if (!$visitor['is_moderator'])
        {
            throw $this->getNoPermissionResponseException();
        }
 

Cyb3r

Well-known member
#2
If you have a usergroup permission for that page you can use this:

PHP:
// Check user group permissions
if (!$visitor->hasPermission('Permission_Group', 'Permission_Name'))
{
    throw $this->getNoPermissionResponseException();
}
Otherwise you can check his usergroups like this:

Code:
if (!$visitor->isMemberOf(4))
{
    throw $this->getNoPermissionResponseException();
}
Change number 4 to the allowed usergroup, if you want to add more usergroups replace the number 4 with array(4,3) you can add more groups by adding their group_id separating them by comma.