Auto Accept Friend Requests

Hello,

On Buddypress, I would like friendship requests to automatically accept so the user does not have to accept the request.

function bp_auto_accept_friend_request( $friendship_id, $friendship_initiator_id, $friendship_friend_id ) {
$friendship_status = BP_Friends_Friendship::check_is_friend( $friendship_initiator_id, $friendship_friend_id );
if ( 'pending' == $friendship_status ) {
// force add
friends_add_friend( $friendship_initiator_id, $friendship_friend_id, $force_accept = true );
friends_accept_friendship( $friendship_id );

// Update friend totals
friends_update_friend_totals( $friendship_initiator_id, $friendship_friend_id, 'add' );
}
}
add_action('friends_friendship_requested', 'bp_auto_accept_friend_request', 200, 3);

This works as required. However, the BP buttons still say, "Friendship Requested" even though they are already friends. Any ideas?

    Kimberly

    Not sure if this will help but here a snippet some some custom code for removing the friend notice when accepted, it was used for a different purpose, but maybe it provides some direction:

    * 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' );

JOIN 426222 HAPPY MEMBERS

We pride ourselves on our level of customer support and responsiveness to member requests. Your WordPress experience will never be the same


Start free trial


ABOUT SSL CERTIFICATES