Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress how to make two user friends by their user id via custom code


  • Ankit Joshi
    Participant

    @ankitjoshi11

    Buddypress
    I want to make friendship between two users. I have user A and B. And I am coding in child theme functions.php file.

    If user “A” want to send friendship request to user “B” then I need a code to send friendship request

    And if user “B” accept the request then I need to code to accept friendship request.

    Please suggest me how can I do this and this should be the buddypress add or accept friendship functionality.

    Best Regards,

Viewing 3 replies - 1 through 3 (of 3 total)

  • Boone Gorges
    Keymaster

    @boonebgorges

    Hi @ankitjoshi11 – Check out the file buddypress/bp-friends/bp-friends-functions.php. The functions you’ll need are:

    
    friends_add_friend( $initiator_userid, $friend_userid );
    

    which accepts a third $force_accept parameter which makes it unnecessary for user B to manually accept. If you want to handle acceptance separately, look at

    
    friends_accept_friendship( $friendship_id );
    

    You can get the $friendship_id for two users with friends_get_friendship_id( $user_a, $user_b );

    Good luck with your project!


    Ankit Joshi
    Participant

    @ankitjoshi11

    Thank you Boone Gorges,

    Yes I have checked all the functions but I am working in child theme functions.php file and buddypress friends_add_friend function is not working in this file directly. DO I need to import any file here?

    So can you please let me know


    Boone Gorges
    Keymaster

    @boonebgorges

    BP’s functions may not be completely loaded by the time functions.php is loaded, so it may not be possible to run directly in functions.php. That being said, there is very little that you should be doing directly in functions.php, aside from calls to add_filter() or add_action(). Similarly, your friend actions should take place inside of a callback:

    
    add_action( 'bp_ready', function() {
        // your custom code
    } );
    

    If you’re continuing to have problems, please share the exact code that you are using and maybe someone on this thread will be able to provide more direct advice.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar