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

how to check user group permission in my addon

#1
i have created a new permission with all user group permission through Permission Definitions

....i want to check for permission that i create ...in extended resource controller ..how it is possible...is there any function that will check for particular permission id..
 

tyteen4a03

Well-known member
#2
First you will need to get the permissions for the user (XenForo_Visitor::getInstance()->toArray()["permissions"]), then use XenForo_Permissions::hasPermission(permissionArray, permissionGroup, permissionID) to check whether the user has permissions. Additionally, a shortcut XenForo_Visitor::getInstance()->hasPermission(permissionGroup, permissionID) is also available.

I highly recommend you to dig around XF's code to see it in action.
 

AndyB

Well-known member
#3
Here's an example from my Show Deleted add-on.

In this case I'm checking to see if the user has the permission to view soft deleted posts and threads.

PHP:
    // get permissions
     $permissions = XenForo_Visitor::getInstance()->getPermissions();
     
     // get viewDeleted permission
     $viewDeleted = XenForo_Permission::hasPermission($permissions, "forum", "viewDeleted");
     
     // if viewDeleted is false display no permission response
     if (!$viewDeleted)
     {
       throw $this->getNoPermissionResponseException();
     }