Notifications
Clear all

Script [Solved] Show Only One Group to Guests

3 Posts
2 Users
2 Reactions
134 Views
Danno6116
Posts: 79
Topic starter
(@danno6116)
Estimable Member
Joined: 2 years ago

Hello everyone., 

My platform uses wpForo with the Custom User Fields plugin. I need visitors (not logged in) to see only one specific group and its member cards when they land on the site, while the rest of the global member database remains hidden until login.

Because the member database is global, I’ve spent hours trying different methods and even tested-added a second board without success.

Can anyone provide guidance on how to restrict all other groups and member cards until after login, while allowing public visibility to just this one group?

Thank you,


2 Replies
Robert
Posts: 10660
Admin
(@robert)
Support Team
Joined: 10 years ago

Hi @danno6116 

The best approach is to use the wpforo_current_object_members_args_filter hook to restrict which usergroups guests can see.

Here is a code snippet you can try. Put it in Code Snippets plugin (PHP) or directly in the current active functions.php file. Change th 5 to any user group ID you want. If they are multiple, you can separate them by comma [5, 6, 7]:

/**
 * Restrict member list visibility for guests to a single usergroup
 * 
 * @param array $args   Member query arguments
 * @param array $get    GET parameters
 * @return array        Modified arguments
 */
add_filter( 'wpforo_current_object_members_args_filter', function( $args, $get ) {
    // Only apply to guests (not logged in users)
    if( empty( WPF()->current_userid ) ) {
        // Replace 5 with YOUR target usergroup ID that guests should see
        $args['groupids'] = [ 5 ];
    }
    return $args;
}, 10, 2 );

 


Reply
Danno6116
Posts: 79
Topic starter
(@danno6116)
Estimable Member
Joined: 2 years ago

@robert Thank you very much Sir It is very Appreciated! Seems to work very well if I have any issues I'll let you know but thank you


Reply