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

Check for usergroup?

Discussion in 'XenForo Development Discussions' started by overifist, Dec 4, 2015.

  1. overifist

    overifist Member

    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();
            }
    
     
  2. Cyb3r

    Cyb3r Well-Known Member

    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.
     
    Robust and overifist like this.

Share This Page