bp_blogs_post_type_remove_comment

Remove a synced activity comment from the activity stream.

Description

bp_blogs_post_type_remove_comment( (bool) $deleted, (int) $comment_id, (object) $activity_post_object, (string) $activity_type = '' ); 

Parameters (4)

0. $deleted (bool)
True when a comment post type activity was successfully removed.
1. $comment_id (int)
ID of the comment to be removed.
2. $activity_post_object (object)
The post type tracking args object.
3. $activity_type — Optional. (string) => ''
The post type comment activity type.

Usage

  1. if ( !function_exists( 'bp_blogs_post_type_remove_comment' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-functions.php'; 
  3.  
  4. // True when a comment post type activity was successfully removed. 
  5. $deleted = true; 
  6.  
  7. // ID of the comment to be removed. 
  8. $comment_id = -1; 
  9.  
  10. // The post type tracking args object. 
  11. $activity_post_object = null; 
  12.  
  13. // The post type comment activity type. 
  14. $activity_type = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bp_blogs_post_type_remove_comment($deleted, $comment_id, $activity_post_object, $activity_type); 
  18.  

Defined (1)

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

/bp-blogs/bp-blogs-functions.php  
  1. function bp_blogs_post_type_remove_comment( $deleted, $comment_id, $activity_post_object, $activity_type = '' ) { 
  2. // Remove synced activity comments, if needed. 
  3. // Get associated activity ID from comment meta 
  4. $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 
  5.  
  6. /** 
  7. * Delete the associated activity comment & also remove 
  8. * child post comments and associated activity comments. 
  9. */ 
  10. if ( ! empty( $activity_id ) ) { 
  11. // fetch the activity comments for the activity item 
  12. $activity = bp_activity_get( array( 
  13. 'in' => $activity_id,  
  14. 'display_comments' => 'stream',  
  15. 'spam' => 'all',  
  16. ) ); 
  17.  
  18. // get all activity comment IDs for the pending deleted item 
  19. if ( ! empty( $activity['activities'] ) ) { 
  20. $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 
  21. $activity_ids[] = $activity_id; 
  22.  
  23. // delete activity items 
  24. foreach ( $activity_ids as $activity_id ) { 
  25. 'id' => $activity_id 
  26. ) ); 
  27.  
  28. // remove associated blog comments 
  29.  
  30. // rebuild activity comment tree 
  31. BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id ); 
  32.  
  33. // Set the result 
  34. $deleted = true; 
  35.  
  36. // Backcompat for comments about the 'post' post type. 
  37. if ( 'new_blog_comment' === $activity_type ) { 
  38. /** 
  39. * Fires after a blog comment activity item was removed from activity stream. 
  40. * @since 1.0.0 
  41. * @param int $value ID for the blog associated with the removed comment. 
  42. * @param int $comment_id ID of the comment being removed. 
  43. * @param int $value ID of the current logged in user. 
  44. */ 
  45. do_action( 'bp_blogs_remove_comment', get_current_blog_id(), $comment_id, bp_loggedin_user_id() ); 
  46.  
  47. return $deleted;