Skip to:
Content

BuddyPress.org

Ticket #6577: 6577.01.patch

File 6577.01.patch, 2.2 KB (added by r-a-y, 6 years ago)
  • src/bp-friends/bp-friends-filters.php

     
    3434        // Fetch whether or not the user is a friend of the current user
    3535        $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids_sql} ) ) OR (initiator_user_id IN ( {$user_ids_sql} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) );
    3636
     37        // Keep track of members that have a friendship status with the current user
     38        $friend_user_ids = array();
     39
    3740        // The "friend" is the user ID in the pair who is *not* the logged in user
    3841        foreach ( (array) $friend_status as $fs ) {
    3942                $friend_id = bp_loggedin_user_id() == $fs->initiator_user_id ? $fs->friend_user_id : $fs->initiator_user_id;
     43                $friend_user_ids[] = $friend_id;
    4044
    4145                if ( isset( $user_query->results[ $friend_id ] ) ) {
    4246                        if ( 0 == $fs->is_confirmed ) {
     
    4953                        $user_query->results[ $friend_id ]->friendship_status = $status;
    5054                }
    5155        }
     56
     57        // The rest are not friends with the current user, so set status accordingly
     58        $not_friends = array_diff( explode( ',', $user_ids_sql ), $friend_user_ids );
     59        foreach ( (array) $not_friends as $nf ) {
     60                if ( bp_loggedin_user_id() == $nf ) {
     61                        continue;
     62                }
     63                $user_query->results[ $nf ]->friendship_status = 'not_friends';
     64        }
     65
    5266}
    5367add_filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 );
  • src/bp-friends/bp-friends-functions.php

     
    282282        if ( ! empty( $members_template->in_the_loop ) ) {
    283283                if ( isset( $members_template->member->friendship_status ) ) {
    284284                        return $members_template->member->friendship_status;
    285 
    286                 // make sure that the friends BP_User_Query was registered before assuming
    287                 // status as 'not_friends'
    288                 } elseif ( has_filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras' ) ) {
    289                         return 'not_friends';
    290285                }
    291286        }
    292287