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