BuddyDev

Search

[Resolved] Excluding current logged in user from members widget?


  • Participant
    Level: Initiated
    Posts: 19
    Alayna on #3688

    Hello again.

    I have been searching for how to exclude the current logged in user from the members widget. I just came across Brajesh’s great post https://buddydev.com/buddypress/hiding-users-on-buddypress-based-site/ that shows how to do it for various user IDs or roles, however I just need to exclude bp_loggedin_user_id … How can I do that?

    Thanks in advance for your help as always!


  • Keymaster
    Level: Guru
    (BuddyDev Team)
    Posts: 894
    Ravi on #3689

    Hi Alayna,

    Thank you for posting. Please use the following code in your bp-custom.php and let me know if it works or not

    
    
    function buddydev_exclude_users( $args ) {
    	//do not exclude in admin
    	if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
    		return $args;
    	}
    
    	$excluded = isset( $args['exclude'] )? $args['exclude'] : array();
    
    	if( !is_array( $excluded ) ) {
    		$excluded = explode(',', $excluded );
    	}
    
    	$user_ids = array( bp_loggedin_user_id() ); //user ids
    
    	$excluded = array_merge( $excluded, $user_ids );
    
    	$args['exclude'] = $excluded;
    
    	return $args;
    }
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users' );
    
    

    Thank You
    Ravi


  • Participant
    Level: Initiated
    Posts: 19
    Alayna on #3694

    Works perfectly, thank you! 🙂


  • Keymaster
    Level: Guru
    (BuddyDev Team)
    Posts: 894
    Ravi on #3695

    Hi Alayna,

    Thank You for confirming.

    Thank You
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved
Subscribe