function friends_add_friend($initiator_userid, $friend_userid, $force_accept = false) { global $bp; $friendship = new BP_Friends_Friendship(); if ((int) $friendship->is_confirmed) { return true; } $friendship->initiator_user_id = $initiator_userid; $friendship->friend_user_id = $friend_userid; $friendship->is_confirmed = 0; $friendship->is_limited = 0; $friendship->date_created = bp_core_current_time(); if ($force_accept) { $friendship->is_confirmed = 1; } if ($friendship->save()) { if (!$force_accept) { // Add the on screen notification bp_core_add_notification($friendship->initiator_user_id, $friendship->friend_user_id, $bp->friends->id, 'friendship_request'); // Send the email notification friends_notification_new_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id); do_action('friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id); } else { do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id); } return true; } return false; }
function friends_add_friend($initiator_userid, $friend_userid) { global $bp; /* Check the nonce */ if (!check_admin_referer('friends_add_friend')) { return false; } $friendship = new BP_Friends_Friendship(); if ((int) $friendship->is_confirmed) { return true; } $friendship->initiator_user_id = $initiator_userid; $friendship->friend_user_id = $friend_userid; $friendship->is_confirmed = 0; $friendship->is_limited = 0; $friendship->date_created = time(); if ($friendship->save()) { // Add the on screen notification bp_core_add_notification($friendship->initiator_user_id, $friendship->friend_user_id, 'friends', 'friendship_request'); // Send the email notification require_once BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php'; friends_notification_new_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id); do_action('friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id); return true; } return false; }