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.


Parameters 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


Top ↑

Return Return

(array) $fids IDs of friends for provided user.


Source 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 );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.