bp_friends_filter_user_query_populate_extras( BP_User_Query $user_query, string $user_ids_sql )
Filter BP_User_Query::populate_extras to add confirmed friendship status.
Description
Each member in the user query is checked for confirmed friendship status against the logged-in user.
Parameters
- $user_query
-
(Required) The BP_User_Query object.
- $user_ids_sql
-
(Required) Comma-separated list of user IDs to fetch extra data for, as determined by BP_User_Query.
Source
File: bp-friends/bp-friends-filters.php
function bp_friends_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) {
global $wpdb;
// Stop if user isn't logged in.
if ( ! $user_id = bp_loggedin_user_id() ) {
return;
}
$maybe_friend_ids = wp_parse_id_list( $user_ids_sql );
// Bulk prepare the friendship cache.
BP_Friends_Friendship::update_bp_friends_cache( $user_id, $maybe_friend_ids );
foreach ( $maybe_friend_ids as $friend_id ) {
$status = BP_Friends_Friendship::check_is_friend( $user_id, $friend_id );
$user_query->results[ $friend_id ]->friendship_status = $status;
if ( 'is_friend' == $status ) {
$user_query->results[ $friend_id ]->is_friend = 1;
}
}
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.7.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.