function friends_accept_friendship($friendship_id)
{
    global $bp;
    $friendship = new BP_Friends_Friendship($friendship_id, true, false);
    if (!$friendship->is_confirmed && BP_Friends_Friendship::accept($friendship_id)) {
        friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id);
        // Remove the friend request notice
        bp_core_delete_notifications_by_item_id($friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request');
        // Add a friend accepted notice for the initiating user
        bp_core_add_notification($friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted');
        $initiator_link = bp_core_get_userlink($friendship->initiator_user_id);
        $friend_link = bp_core_get_userlink($friendship->friend_user_id);
        // Record in activity streams for the initiator
        friends_record_activity(array('user_id' => $friendship->initiator_user_id, 'type' => 'friendship_created', 'action' => apply_filters('friends_activity_friendship_accepted_action', sprintf(__('%1$s and %2$s are now friends', 'buddypress'), $initiator_link, $friend_link), $friendship), 'item_id' => $friendship_id, 'secondary_item_id' => $friendship->friend_user_id));
        // Record in activity streams for the friend
        friends_record_activity(array('user_id' => $friendship->friend_user_id, 'type' => 'friendship_created', 'action' => apply_filters('friends_activity_friendship_accepted_action', sprintf(__('%1$s and %2$s are now friends', 'buddypress'), $friend_link, $initiator_link), $friendship), 'item_id' => $friendship_id, 'secondary_item_id' => $friendship->initiator_user_id, 'hide_sitewide' => true));
        // Send the email notification
        friends_notification_accepted_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        return true;
    }
    return false;
}
Example #2
0
/**
 * Mark a friendship request as accepted.
 *
 * Also initiates a "friendship_accepted" activity item.
 *
 * @param int $friendship_id ID of the pending friendship object.
 * @return bool True on success, false on failure.
 */
function friends_accept_friendship($friendship_id)
{
    // Get the friesdhip data
    $friendship = new BP_Friends_Friendship($friendship_id, true, false);
    // Accepting friendship
    if (empty($friendship->is_confirmed) && BP_Friends_Friendship::accept($friendship_id)) {
        // Bump the friendship counts
        friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id);
        do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship);
        return true;
    }
    return false;
}
/**
 * Mark a friendship request as accepted.
 *
 * Also initiates a "friendship_accepted" activity item.
 *
 * @since 1.0.0
 *
 * @param int $friendship_id ID of the pending friendship object.
 * @return bool True on success, false on failure.
 */
function friends_accept_friendship($friendship_id)
{
    // Get the friendship data.
    $friendship = new BP_Friends_Friendship($friendship_id, true, false);
    // Accepting friendship.
    if (empty($friendship->is_confirmed) && BP_Friends_Friendship::accept($friendship_id)) {
        // Bump the friendship counts.
        friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id);
        /**
         * Fires after a friendship is accepted.
         *
         * @since 1.0.0
         *
         * @param int    $id                ID of the pending friendship object.
         * @param int    $initiator_user_id ID of the friendship initiator.
         * @param int    $friend_user_id    ID of the user requested friendship with.
         * @param object $friendship        BuddyPress Friendship Object.
         */
        do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship);
        return true;
    }
    return false;
}
Example #4
0
function friends_accept_friendship($friendship_id)
{
    /* Check the nonce */
    if (!check_admin_referer('friends_accept_friendship')) {
        return false;
    }
    $friendship = new BP_Friends_Friendship($friendship_id, true, false);
    if (!$friendship->is_confirmed && BP_Friends_Friendship::accept($friendship_id)) {
        friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id);
        // Remove the friend request notice
        bp_core_delete_notifications_for_user_by_item_id($friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_request');
        // Add a friend accepted notice for the initiating user
        bp_core_add_notification($friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_accepted');
        // Record in activity streams
        friends_record_activity(array('item_id' => $friendship_id, 'component_name' => $bp->friends->slug, 'component_action' => 'friendship_accepted', 'is_private' => 0, 'user_id' => $friendship->initiator_user_id, 'secondary_user_id' => $friendship->friend_user_id));
        // Send the email notification
        require_once BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php';
        friends_notification_accepted_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        return true;
    }
    return false;
}