BP_Friends_Friendship::get_friend_user_ids( int $user_id, bool $friend_requests_only = false, bool $assoc_arr = false )
Get the IDs of a given user’s friends.
Description
Parameters
- $user_id
-
(int) (Required) ID of the user whose friends are being retrieved.
- $friend_requests_only
-
(bool) (Optional) Whether to fetch unaccepted requests only. Default: false.
Default value: false
- $assoc_arr
-
(bool) (Optional) True to receive an array of arrays keyed as 'user_id' => $user_id; false to get a one-dimensional array of user IDs. Default: false.
Default value: false
Return
(array) $fids IDs of friends for provided user.
Source
File: bp-friends/classes/class-bp-friends-friendship.php
public static function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) { global $wpdb; if ( ! empty( $friend_requests_only ) ) { $args = array( 'is_confirmed' => 0, 'friend_user_id' => $user_id ); } else { $args = array( 'is_confirmed' => 1, ); } $friendships = self::get_friendships( $user_id, $args ); $fids = array(); foreach ( $friendships as $friendship ) { if ( ! empty( $assoc_arr ) ) { $fids[] = array( 'user_id' => ( $friendship->friend_user_id == $user_id ) ? $friendship->initiator_user_id : $friendship->friend_user_id ); } else { $fids[] = ( $friendship->friend_user_id == $user_id ) ? $friendship->initiator_user_id : $friendship->friend_user_id; } } return array_map( 'intval', $fids ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.0.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.