/**
 * Check whether a given user is a friend of the logged-in user.
 *
 * Returns - 'is_friend', 'not_friends', 'pending'.
 *
 * @param int $user_id ID of the potential friend. Default: the value of
 *                     {@link bp_get_potential_friend_id()}.
 * @return string 'is_friend', 'not_friends', or 'pending'.
 */
function bp_is_friend($user_id = 0)
{
    if (!is_user_logged_in()) {
        return false;
    }
    if (empty($user_id)) {
        $user_id = bp_get_potential_friend_id($user_id);
    }
    if (bp_loggedin_user_id() == $user_id) {
        return false;
    }
    /**
     * Filters the status of friendship between logged in user and given user.
     *
     * @since 1.2.10
     *
     * @param string $value String status of friendship. Possible values are 'is_friend', 'not_friends', 'pending'.
     */
    return apply_filters('bp_is_friend', friends_check_friendship_status(bp_loggedin_user_id(), $user_id), $user_id);
}
/**
 * bp_is_friend( $user_id )
 *
 * Returns - 'is_friend', 'not_friends', 'pending'
 *
 * @param int $potential_friend_id
 * @return string
 */
function bp_is_friend($user_id = 0)
{
    if (!is_user_logged_in()) {
        return false;
    }
    if (empty($user_id)) {
        $user_id = bp_get_potential_friend_id($user_id);
    }
    if (bp_loggedin_user_id() == $user_id) {
        return false;
    }
    return apply_filters('bp_is_friend', friends_check_friendship_status(bp_loggedin_user_id(), $user_id), $user_id);
}
예제 #3
0
 /**
  * @group friends_check_friendship_status
  */
 public function test_friends_check_friendship_status_not_in_members_loop()
 {
     $now = time();
     $u1 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now)));
     $u2 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 100)));
     $u3 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 200)));
     $u4 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 300)));
     $u5 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 400)));
     friends_add_friend($u1, $u2, true);
     friends_add_friend($u1, $u3, false);
     friends_add_friend($u4, $u1, false);
     $found = array($u1 => friends_check_friendship_status($u1, $u1), $u2 => friends_check_friendship_status($u1, $u2), $u3 => friends_check_friendship_status($u1, $u3), $u4 => friends_check_friendship_status($u1, $u4), $u5 => friends_check_friendship_status($u1, $u5));
     $expected = array($u1 => 'not_friends', $u2 => 'is_friend', $u3 => 'pending', $u4 => 'awaiting_response', $u5 => 'not_friends');
     $this->assertSame($expected, $found);
 }
예제 #4
0
 function set_privacy($profile)
 {
     if (is_rt_admin()) {
         return 60;
     }
     $user = $this->visitor_id();
     $privacy = 0;
     if ($user) {
         $privacy = 20;
     }
     if ($profile === false) {
         $profile = $this->profile_id();
     }
     if (class_exists('BuddyPress') && bp_is_active('friends')) {
         if (friends_check_friendship_status($user, $profile)) {
             $privacy = 40;
         }
     }
     if ($user === $profile) {
         $privacy = 60;
     }
     return $privacy;
 }
예제 #5
0
function bp_are_friends($other_id, $user_id)
{
    $friend_status = friends_check_friendship_status($user_id, $other_id);
    return $friend_status == 'is_friend' || $user_id == $other_id;
}
예제 #6
0
 /**
  * @group friendship_caching
  */
 public function test_friends_check_friendship_should_hit_friendship_object_cache()
 {
     global $wpdb;
     $now = time();
     $u1 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now)));
     $u2 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 100)));
     friends_add_friend($u1, $u2, true);
     friends_check_friendship_status($u1, $u2);
     $first_query_count = $wpdb->num_queries;
     /*
      * We expect this to generate one query to find $u2's friendships,
      * but the friendship object itself should come from cache.
      */
     friends_check_friendship_status($u2, $u1);
     $this->assertEquals($first_query_count + 1, $wpdb->num_queries);
 }
function bp_checkins_get_friends_checkedin()
{
    global $bp;
    $output = "";
    if (!(int) bp_get_option('bp-checkins-enable-box-checkedin-friends') || '' == bp_get_option('bp-checkins-enable-box-checkedin-friends')) {
        return $output;
    }
    if (!is_user_logged_in()) {
        return $output;
    }
    $place_id = bp_get_checkins_places_id();
    $args = array('filter' => array('action' => 'place_checkin', 'primary_id' => $place_id));
    $activities = bp_activity_get($args);
    $friends_checkin = array();
    foreach ($activities['activities'] as $checkedin) {
        if ($checkedin->user_id != $bp->loggedin_user->id && 'is_friend' == friends_check_friendship_status($bp->loggedin_user->id, $checkedin->user_id)) {
            // as people can checkin several times 1 each 12 hours...
            if (!in_array($checkedin->user_id, $friends_checkin)) {
                $friends_checkin[] = $checkedin->user_id;
            }
        }
    }
    shuffle($friends_checkin);
    if (count($friends_checkin) >= 1) {
        $output = '<br style="clear:both"><div class="checkedin-amigos">' . __('Great! Some of your friends checked in this place.', 'bp-checkins') . '<ul>';
        $step = 0;
        $max = apply_filters('bp_checkins_max_friends_checkedin', 5);
        foreach ($friends_checkin as $friend_id) {
            if ($step == $max) {
                break;
            }
            $output .= '<li><a href="' . bp_core_get_userlink($friend_id, false, true) . '">' . bp_core_fetch_avatar(array('item_id' => $friend_id, 'object' => 'user', 'type' => 'thumb', 'class' => 'avatar checkedin_friend', 'width' => '40', 'height' => '40')) . '</a></li>';
            $step += 1;
        }
        $output .= '</ul><br style="clear:both"></div>';
    }
    return apply_filters('bp_checkins_get_friends_checkedin', $output, $friends_checkin);
}
예제 #8
0
/**
 * bp_is_friend( $user_id )
 *
 * Returns - 'is_friend', 'not_friends', 'pending'
 *
 * @global object $bp
 * @param int $potential_friend_id
 * @return string
 */
function bp_is_friend( $user_id = 0 ) {
	global $bp;

	if ( !is_user_logged_in() )
		return false;

	if ( empty( $user_id ) )
		$user_id = bp_get_potential_friend_id( $user_id );

	if ( $bp->loggedin_user->id == $user_id )
		return false;

	return apply_filters( 'bp_is_friend', friends_check_friendship_status( $bp->loggedin_user->id, $user_id ), $user_id );
}