BP_Friends_Friendship::get_friendship_id( int $user_id, int $friend_id )

Get the ID of the friendship object, if any, between a pair of users.

Description

Parameters

$user_id

(Required) The ID of the first user.

$friend_id

(Required) The ID of the second user.

Return

(int|null) The ID of the friendship object if found, otherwise null.

Source

File: bp-friends/classes/class-bp-friends-friendship.php

427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
public static function get_friendship_id( $user_id, $friend_id ) {
    $friendship_id = null;
 
    // Can't friend yourself.
    if ( $user_id == $friend_id ) {
        return $friendship_id;
    }
 
    /*
     * Find friendships where the possible_friend_userid is the
     * initiator or friend.
     */
    $args = array(
        'initiator_user_id' => $friend_id,
        'friend_user_id'    => $friend_id
    );
    $result = self::get_friendships( $user_id, $args, 'OR' );
    if ( $result ) {
        $friendship_id = current( $result )->id;
    }
    return $friendship_id;
}

Changelog

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.