friends_accept_friendship

Mark a friendship request as accepted.

Description

friends_accept_friendship( (int) $friendship_id ); 

Also initiates a friendship_accepted activity item.

Parameters (1)

0. $friendship_id (int)
ID of the pending friendship object.

Usage

  1. if ( !function_exists( 'friends_accept_friendship' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-friends/bp-friends-functions.php'; 
  3.  
  4. // ID of the pending friendship object. 
  5. $friendship_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = friends_accept_friendship($friendship_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-friends/bp-friends-functions.php  
  1. function friends_accept_friendship( $friendship_id ) { 
  2.  
  3. // Get the friendship data. 
  4. $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 
  5.  
  6. // Accepting friendship. 
  7. if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::accept( $friendship_id ) ) { 
  8.  
  9. // Bump the friendship counts. 
  10. friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id ); 
  11.  
  12. /** 
  13. * Fires after a friendship is accepted. 
  14. * @since 1.0.0 
  15. * @param int $id ID of the pending friendship object. 
  16. * @param int $initiator_user_id ID of the friendship initiator. 
  17. * @param int $friend_user_id ID of the user requested friendship with. 
  18. * @param object $friendship BuddyPress Friendship Object. 
  19. */ 
  20. do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship ); 
  21.  
  22. return true; 
  23.  
  24. return false;