Skip to:
Content
Pages
Categories
Search
Top
Bottom

Auto Accept Friend Requests

  • Avatar of userabuser
    userabuser
    Participant

    @userabuser

    Hi everyone,

    Note: I’m offering a $50 bounty to anyone who can answer this question. This question is also active on WPSE located here

    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…

    Note: Currently using WordPress 3.5 and BuddyPress 1.6.4

You must be logged in to reply to this topic.