Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/07/2015 05:52:08 AM (6 years ago)
Author:
r-a-y
Message:

Friends: Fix issue with using friends_check_friendship_status() during the members loop when the legacy user query is enabled.

Previously, if the legacy user query was enabled, the friendship button in
the members loop would always return "Add Friend" regardless of the actual
friendship status.

This commit fixes this by setting the 'not_friends' status inside the
the bp_friends_filter_user_query_populate_extras() function instead of
in friends_check_friendship_status().

Fixes #6577.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/bp-friends-filters.php

    r9995 r10037  
    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 ] ) ) {
     
    5054        }
    5155    }
     56
     57    // The rest are not friends with the current user, so set status accordingly
     58    $not_friends = array_diff( $user_query->user_ids, $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 );
Note: See TracChangeset for help on using the changeset viewer.