Skip to:
Content

BuddyPress.org

Changeset 10037


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.

Location:
trunk/src/bp-friends
Files:
2 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 );
  • trunk/src/bp-friends/bp-friends-functions.php

    r9995 r10037  
    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    }
Note: See TracChangeset for help on using the changeset viewer.