BuddyDev

Search

[Resolved] hiding users by id, not just admins

  • Participant
    Level: Enlightened
    Posts: 46
    Kristian Yngve on #22080

    I am already using the hide admins code which has been specially customized to work with the paid plugin: BuddyBlock due to past interferences…

    My hide admin code is below, but how to also hide any users by ID, while also hiding all admins?:

     function pp_filter_members( $query_array ) { 
    
    	$excluded = array();
    
    	if ( isset( $query_array->query_vars['exclude'] ) ) {
    
    		$excluded = $query_array->query_vars['exclude'];
    
    	}
    
        if ( ! is_array( $excluded ) ) {
            $excluded = explode( ',', $excluded );
        }
    
        $role     = 'administrator';	// change to the role to be excluded.
        $user_ids = get_users( array( 'role' => $role, 'fields' => 'ID' ) );
     
        $new_excluded = array_merge( $excluded, $user_ids );
    
    	$query_array->query_vars['exclude'] = $new_excluded;
    
    }
    add_action( 'bp_pre_user_query_construct', 'pp_filter_members', 99, 1 ); 

    .

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #22083

    Hi Kristian,
    Thank you for teh question.

    Please change this line

    
    
    $new_excluded = array_merge( $excluded, $user_ids );
    
    

    to

    
    $other_ids = array( 1,2,3,4,5); //update it with correct ids
    
    $new_excluded = array_merge( $excluded, $user_ids, $other_ids );
    
    

    That should do it.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 46
    Kristian Yngve on #22097

    Thank you, Brajesh!

    As always, your code works perfectly.

    Best,

    Kristian

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #22106

    Thank you 🙂

The topic ‘ [Resolved] hiding users by id, not just admins’ is closed to new replies.

This topic is: resolved