friends_remove_friend

Remove a friendship.

Description

friends_remove_friend( (int) $initiator_userid, (int) $friend_userid ); 

Will also delete the related friendship_accepted activity item.

Parameters (2)

0. $initiator_userid (int)
ID of the friendship initiator.
1. $friend_userid (int)
ID of the friend user.

Usage

  1. if ( !function_exists( 'friends_remove_friend' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-friends/bp-friends-functions.php'; 
  3.  
  4. // ID of the friendship initiator. 
  5. $initiator_userid = -1; 
  6.  
  7. // ID of the friend user. 
  8. $friend_userid = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = friends_remove_friend($initiator_userid, $friend_userid); 
  12.  

Defined (1)

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

/bp-friends/bp-friends-functions.php  
  1. function friends_remove_friend( $initiator_userid, $friend_userid ) { 
  2.  
  3. $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid ); 
  4. $friendship = new BP_Friends_Friendship( $friendship_id ); 
  5.  
  6. /** 
  7. * Fires before the deletion of a friendship activity item 
  8. * for the user who canceled the friendship. 
  9. * @since 1.5.0 
  10. * @param int $friendship_id ID of the friendship object, if any, between a pair of users. 
  11. * @param int $initiator_userid ID of the friendship initiator. 
  12. * @param int $friend_userid ID of the friend user. 
  13. */ 
  14. do_action( 'friends_before_friendship_delete', $friendship_id, $initiator_userid, $friend_userid ); 
  15.  
  16. // Remove the activity stream items about the friendship id. 
  17. friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_created', 'user_id' => 0 ) ); 
  18.  
  19. /** 
  20. * Fires before the friendship connection is removed. 
  21. * This hook is misleadingly named - the friendship is not yet deleted. 
  22. * This is your last chance to do something while the friendship exists. 
  23. * @since 1.0.0 
  24. * @param int $friendship_id ID of the friendship object, if any, between a pair of users. 
  25. * @param int $initiator_userid ID of the friendship initiator. 
  26. * @param int $friend_userid ID of the friend user. 
  27. */ 
  28. do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid ); 
  29.  
  30. if ( $friendship->delete() ) { 
  31. friends_update_friend_totals( $initiator_userid, $friend_userid, 'remove' ); 
  32.  
  33. /** 
  34. * Fires after the friendship connection is removed. 
  35. * @since 1.8.0 
  36. * @param int $initiator_userid ID of the friendship initiator. 
  37. * @param int $friend_userid ID of the friend user. 
  38. */ 
  39. do_action( 'friends_friendship_post_delete', $initiator_userid, $friend_userid ); 
  40.  
  41. return true; 
  42.  
  43. return false;