Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to Exclude already friends in all members directory ?


  • Neev07
    Participant

    @neev07

    Hey,
    Is there any way to exclude already friends from members directory but keeping them in user’s friend list.

    Brajesh (buddydev) suggested me a code but that is excluding friends from a user’s friend list also due to which a user gets a error ‘sorry there is no member’. And I am not able to modify the code. I hope someone would help me.

    This is the code:

    add_filter( 'bp_after_has_members_parse_args', 'devb_custom_hide_friends' );
    
    function devb_custom_hide_friends( $args ) {
    
        //do not hide friends in friend list
        if ( ! is_user_logged_in() || isset( $args['scope'] ) && $args['scope'] =='personal' ) {
            return $args;
        }
    
        $friends = 	friends_get_friend_user_ids( get_current_user_id() );
    
        if ( empty( $friends ) ) {
            return $args;
        }
    
        $excluded = !empty( $args['exclude'] ) ? $args['exclude'] : array();
    
        if (is_string( $excluded ) ) {
            $excluded = explode(',', $excluded );
        }
    
        $excluded = array_merge( $friends, $excluded );
    
        $args['exclude'] = $excluded;
    
        return $args;
    }

    Please reply as soon as possible.

    Thanks,
    Nitin

Viewing 2 replies - 1 through 2 (of 2 total)

  • Henry Wright
    Moderator

    @henrywright

    Try using bp_is_directory(). So:

    add_filter( 'bp_after_has_members_parse_args', 'devb_custom_hide_friends' );
    
    function devb_custom_hide_friends( $args ) {
        if ( ! bp_is_directory() ) {
            return $args;
        }
        // Rest of your code.

    Neev07
    Participant

    @neev07

    Thanks a lot for this code….. 🙂 …. it worked very well 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar