Mouth
Well-known member
Hi,
Trying to check if a user is a member of a usergroup, and perform an action (deny access) if they are not, within PHP outside of XF templates. Here's the code ....
You can see I commented out
because it only checked on the users primary usergroup, and not also any secondary usergroups.
throws an error and does not work.
Would appreciate some assistance with what I should be doing here?
Thanks.
Trying to check if a user is a member of a usergroup, and perform an action (deny access) if they are not, within PHP outside of XF templates. Here's the code ....
PHP:
$mouthUser = $userModel->getUserById($userId);
$mouthAllow = array(3,4,17,29);
$mouthErrorMessage = "Sorry, only specific usergroups are able to access";
//if(!in_array($mouthUser['user_group_id'], $mouthAllow))
if(!$mouthUser->isMemberOf($mouthAllow))
return xmlresperror($mouthErrorMessage);
You can see I commented out
PHP:
if(!in_array($mouthUser['user_group_id'], $mouthAllow))
PHP:
if(!$mouthUser->isMemberOf($mouthAllow))
Would appreciate some assistance with what I should be doing here?
Thanks.