bp_activity_delete_comment

Delete an activity comment.

Description

bp_activity_delete_comment( (int) $activity_id, (int) $comment_id ); 

Parameters (2)

0. $activity_id (int)
The ID of the root activity, ie the comment's oldest ancestor.
1. $comment_id (int)
The ID of the comment to be deleted.

Usage

  1. if ( !function_exists( 'bp_activity_delete_comment' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // The ID of the "root" activity, ie the comment's 
  5. // oldest ancestor. 
  6. $activity_id = -1; 
  7.  
  8. // The ID of the comment to be deleted. 
  9. $comment_id = -1; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bp_activity_delete_comment($activity_id, $comment_id); 
  13.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_delete_comment( $activity_id, $comment_id ) { 
  2. $deleted = false; 
  3.  
  4. /** 
  5. * Filters whether BuddyPress should delete an activity comment or not. 
  6. * You may want to hook into this filter if you want to override this function and 
  7. * handle the deletion of child comments differently. Make sure you return false. 
  8. * @since 1.2.0 
  9. * @since 2.5.0 Add the deleted parameter (passed by reference) 
  10. * @param bool $value Whether BuddyPress should continue or not. 
  11. * @param int $activity_id ID of the root activity item being deleted. 
  12. * @param int $comment_id ID of the comment being deleted. 
  13. * @param bool $deleted Whether the activity comment has been deleted or not. 
  14. */ 
  15. if ( ! apply_filters_ref_array( 'bp_activity_delete_comment_pre', array( true, $activity_id, $comment_id, &$deleted ) ) ) { 
  16. return $deleted; 
  17.  
  18. // Delete any children of this comment. 
  19. bp_activity_delete_children( $activity_id, $comment_id ); 
  20.  
  21. // Delete the actual comment. 
  22. if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) { 
  23. return false; 
  24. } else { 
  25. $deleted = true; 
  26.  
  27. // Purge comment cache for the root activity update. 
  28. wp_cache_delete( $activity_id, 'bp_activity_comments' ); 
  29.  
  30. // Recalculate the comment tree. 
  31. BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id ); 
  32.  
  33. /** 
  34. * Fires at the end of the deletion of an activity comment, before returning success. 
  35. * @since 1.2.0 
  36. * @param int $activity_id ID of the activity that has had a comment deleted from. 
  37. * @param int $comment_id ID of the comment that was deleted. 
  38. */ 
  39. do_action( 'bp_activity_delete_comment', $activity_id, $comment_id ); 
  40.  
  41. return $deleted;