Changeset 11124 for trunk/src/bp-friends/bp-friends-filters.php
- Timestamp:
- 09/20/2016 02:42:15 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-friends/bp-friends-filters.php
r10417 r11124 29 29 30 30 // Stop if user isn't logged in. 31 if ( ! is_user_logged_in() ) {31 if ( ! $user_id = bp_loggedin_user_id() ) { 32 32 return; 33 33 } 34 34 35 $ bp = buddypress();35 $maybe_friend_ids = wp_parse_id_list( $user_ids_sql ); 36 36 37 // Fetch whether or not the user is a friend of the current user. 38 $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() ) ); 39 40 // Keep track of members that have a friendship status with the current user. 41 $friend_user_ids = array(); 42 43 // The "friend" is the user ID in the pair who is *not* the logged in user. 44 foreach ( (array) $friend_status as $fs ) { 45 $friend_id = bp_loggedin_user_id() == $fs->initiator_user_id ? $fs->friend_user_id : $fs->initiator_user_id; 46 $friend_user_ids[] = $friend_id; 47 48 if ( isset( $user_query->results[ $friend_id ] ) ) { 49 if ( 0 == $fs->is_confirmed ) { 50 $status = $fs->initiator_user_id == bp_loggedin_user_id() ? 'pending' : 'awaiting_response'; 51 } else { 52 $status = 'is_friend'; 53 } 54 55 $user_query->results[ $friend_id ]->is_friend = $fs->is_confirmed; 56 $user_query->results[ $friend_id ]->friendship_status = $status; 57 } 58 } 59 60 // The rest are not friends with the current user, so set status accordingly. 61 $not_friends = array_diff( $user_query->user_ids, $friend_user_ids ); 62 foreach ( (array) $not_friends as $nf ) { 63 if ( bp_loggedin_user_id() == $nf ) { 64 continue; 65 } 66 67 if ( isset( $user_query->results[ $nf ] ) ) { 68 $user_query->results[ $nf ]->friendship_status = 'not_friends'; 37 foreach ( $maybe_friend_ids as $friend_id ) { 38 $status = BP_Friends_Friendship::check_is_friend( $user_id, $friend_id ); 39 $user_query->results[ $friend_id ]->friendship_status = $status; 40 if ( 'is_friend' == $status ) { 41 $user_query->results[ $friend_id ]->is_friend = 1; 69 42 } 70 43 }
Note: See TracChangeset
for help on using the changeset viewer.