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; }
/** * Add activity stream items when one members accepts another members request * for virtual friendship. * * @since 1.9.0 * * @param int $friendship_id ID of the friendship. * @param int $initiator_user_id ID of friendship initiator. * @param int $friend_user_id ID of user whose friendship is requested. * @param object|bool $friendship Optional Friendship object. */ function bp_friends_friendship_accepted_activity($friendship_id, $initiator_user_id, $friend_user_id, $friendship = false) { if (!bp_is_active('activity')) { return; } // Record in activity streams for the initiator. friends_record_activity(array('user_id' => $initiator_user_id, 'type' => 'friendship_created', 'item_id' => $friendship_id, 'secondary_item_id' => $friend_user_id)); }
/** * Add activity stream items when one members accepts another members request * for virtual friendship. * * @since BuddyPress (1.9.0) * * @param int $friendship_id * @param int $initiator_user_id * @param int $friend_user_id * @param object $friendship Optional */ function bp_friends_friendship_accepted_activity($friendship_id, $initiator_user_id, $friend_user_id, $friendship = false) { // Bail if Activity component is not active if (!bp_is_active('activity')) { return; } // Get links to both members profiles $initiator_link = bp_core_get_userlink($initiator_user_id); $friend_link = bp_core_get_userlink($friend_user_id); // Record in activity streams for the initiator friends_record_activity(array('user_id' => $initiator_user_id, 'type' => 'friendship_created', 'item_id' => $friendship_id, 'secondary_item_id' => $friend_user_id)); // Record in activity streams for the friend friends_record_activity(array('user_id' => $friend_user_id, 'type' => 'friendship_created', 'item_id' => $friendship_id, 'secondary_item_id' => $initiator_user_id, 'hide_sitewide' => true)); }
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; }