I'm attempting to create a function that auto accepts friend request in Buddy Press, the function is as follows;
function bp_auto_accept_friend_request( $friendship_id, $friendship_initiator_id, $friendship_friend_id ) {
friends_add_friend(
$friendship_initiator_id,
$friendship_friend_id,
$force_accept = true
);
friends_accept_friendship( $friendship_id );
}
add_action('friends_friendship_requested', 'bp_auto_accept_friend_request', 200, 3);
The above function works by creating an entry in the wp_bp_friends table with a value of 1 for the is_confirmed column, however the default friendship request action is still being executed which adds an additional entry to the table saying unconfirmed.
id initiator_user_id friend_user_id is_confirmed is_limited
2 1 3 1 0
3 1 3 0 0
So we have both a confirmed and unconfirmed entry for the same friendship. This means that on the user profile page it will appear as if you have both a confirmed friend and have a friend request from the same person.
The above function was adapted for simplicity from;
http://premium.wpmudev.org/forums/topic/auto-accept-friend-requests
There's also this accepted answer from WPSE here;
How to auto-accept a friend-request in buddypress based on user meta
...which when adapted to my use case produced the same results described.
Any thoughts on how to prevent the default action? So far I can't unhook the request...
friends_accept_friendship()and track down the related SQL query. Then do a cross file search foris_confirmed. This will help you getting your head around where this else might get triggered. Always make sure that your search below the query when it doesn't get immediately gets executed and above it, when it gets executed. This way you can easily find all related hooks or filters and jump in to abort there. I normally just dump in every hook to see in which order they run. Then just modify or abort there. – kaiser Feb 11 at 7:45