Viewing 3 replies - 1 through 3 (of 3 total)
  • A function that you can put into your theme’s function.php:

    function uam_user_in_group($groupName='', $userId='') {
    	if (empty($userId)) {
    		$userId = get_current_user_id();
    	}
    
        global $userAccessManager;
        if (isset($userAccessManager)) {
            $uamAccessHandler 	= $userAccessManager->getAccessHandler();
            $userGroupsForUser 	= $uamAccessHandler->getUserGroupsForObject('_user_', $userId);
            foreach($userGroupsForUser as $element) {
                if ($element->getName() == $groupName) {
                    return true;
                }
            }
        } else {
            return false;
        }
    }

    And then just call it like this with group name and an optional user id as second parameter:

    if (wsm_uam_user_in_group('MyGroupName')) {
            echo 'User is in group'!;
    } else {
            echo 'User is not in group'!;
    }
    Plugin Author GM_Alex

    (@gm_alex)

    @gm_alex Thank you! I made a little mistake calling the function – I put some dashes in the example output but outside of the quotes ?? So it should rather be:

    if (wsm_uam_user_in_group('MyGroupName')) {
            echo 'User is in group!';
    } else {
            echo 'User is not in group!';
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to tell if the logged in user is in a group?’ is closed to new replies.