1. 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

Discussion in 'XenForo Development Discussions' started by arpitjain, Oct 9, 2013.

  1. arpitjain

    arpitjain Member

    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..
  2. tyteen4a03

    tyteen4a03 Well-Known Member

    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.
    Fethi.dz likes this.
  3. AndyB

    AndyB Well-Known Member

    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.

        // 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)
    Fethi.dz and bousaid like this.
  4. arpitjain

    arpitjain Member

    thank you..its working fine...

Share This Page