Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ) {

        $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;


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...

share|improve this question

closed as off-topic by toscho Aug 2 '14 at 20:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

Take a look into friends_accept_friendship() and track down the related SQL query. Then do a cross file search for is_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 '13 at 7:45

Browse other questions tagged or ask your own question.