• Resolved nickk40

    (@nickk40)


    To hide the Forum from my Menu if the logged in user is not part of any usergroup, I used the following code:

    add_action( 'wp_head', function () { 
    	$current_user_id = get_current_user_id();
    	// Get usergroups of current users 
    	$usergroups = AsgarosForumUserGroups::getUserGroupsOfUser($current_user_id, 'all', true);
    	
    	if (
    		!$current_user_id || !$usergroups
    	) {
    		?><style>.forum-item{display:none!important;}</style><?php	
    	}
    });

    See for this code: https://www.ads-software.com/support/topic/is-there-a-function-to-check-if-logged-in-user-belongs-to-a-usergroup/

    This used to work. However, I suddenly discovered it no longer displays the menu item. If I remove || !$usergroups from the code it does display the menu item. Apparently, it thinks I’m not a user who is part of a usergroup (which I am).

    Has something change in the plugin code? Any suggestions how I should change the code snippet?

Viewing 1 replies (of 1 total)
  • Thread Starter nickk40

    (@nickk40)

    Oh, already found the cause: the usergroup was set to be Hidden and I ran the code snippet only on the frontend.

Viewing 1 replies (of 1 total)
  • The topic ‘Get usergroups of current user’ is closed to new replies.