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 still getting my head around buddypress, so far so good but I’ve hit a snag where I want certain users who are flagged as an ‘expert’ to automatically accept any friend requests people make.

I’ve found a couple of functions related to this but I think I’m missing something that would make this simpler such as setting a constant or overriding part of the $bp global…

What I have so far is the following:

function bp_auto_accept_friend_request( $friendship_id, $friendship_initiator_id, $friendship_friend_id ) {
    if ( is_user_expert( $friendship_friend_id ) ) {
        // force add
        friends_accept_friendship( $friendship_id );
        friends_add_friend( $friendship_initiator_id, $friendship_friend_id, true );
    }
}
add_action('friends_friendship_requested', 'bp_auto_accept_friend_request', 200, 3);

Can anyone tell me where I should be looking to make this nice and seamless just as if the main settings were set to bypass the request process please?

share|improve this question
    
Had no joy with this so far. There's no straight forward way to do it it would seem so I need the help of a BP expert. –  sanchothefat Jan 17 '11 at 14:49
    
I'm not sure but i think you got the functions in a worng order –  Bainternet Jan 17 '11 at 16:40
add comment

1 Answer 1

up vote 1 down vote accepted

UPDATE

try this

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 ( 'not_friends' == $friendship_status ) {
            if ( is_user_expert( $friendship_friend_id ) ) {
            // force add
            friends_add_friend( $friendship_initiator_id, $friendship_friend_id, true );
            friends_accept_friendship( $friendship_id );
        }
        }
    }
    add_action('friends_friendship_requested', 'bp_auto_accept_friend_request', 200, 3);

this way we only call friends_add_friend function with $force = true if they are not friends yet.

share|improve this answer
    
That doesn't do the job I'm afraid. The friendship status and the total friends count don't seem to be updating. –  sanchothefat Jan 18 '11 at 13:16
    
are you sure that is_user_expert is working? and i think i have a lead for you this hook 'friends_friendship_requested' is called after , friends_add_friend function is done, and with this code we are creating an infi loop. so i'll dig some more. –  Bainternet Jan 18 '11 at 17:10
    
i added an update –  Bainternet Jan 18 '11 at 23:28
    
the is_user_expert function works fine. It confused me that the friends_add_friend function was run just to create the friendship record, not when the friendship was confirmed. I'll try out your method. –  sanchothefat Jan 23 '11 at 20:38
    
Let me know how if go's ,I have another angle –  Bainternet Jan 24 '11 at 1:13
add comment

protected by Community May 10 '12 at 2:18

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.