bp_activity_post_type_remove_comment

Remove an activity item when a comment about a post type is deleted.

Description

bp_activity_post_type_remove_comment( (int) $comment_id = 0, (null) $activity_post_object = null ); 

Parameters (2)

0. $comment_id — Optional. (int)
ID of the comment.
1. $activity_post_object — Optional. (null) => null
The post type tracking args object.

Usage

  1. if ( !function_exists( 'bp_activity_post_type_remove_comment' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // ID of the comment. 
  5. $comment_id = -1; 
  6.  
  7. // The post type tracking args object. 
  8. $activity_post_object = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_activity_post_type_remove_comment($comment_id, $activity_post_object); 
  12.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_post_type_remove_comment( $comment_id = 0, $activity_post_object = null ) { 
  2. if ( empty( $activity_post_object ) ) { 
  3. $comment = get_comment( $comment_id ); 
  4. if ( ! $comment ) { 
  5. return; 
  6.  
  7. $post_type = get_post_type( $comment->comment_post_ID ); 
  8. if ( ! $post_type ) { 
  9. return; 
  10.  
  11. // Get the post type tracking args. 
  12. $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type ); 
  13.  
  14. // Bail if the activity type does not exist 
  15. if ( empty( $activity_post_object->comments_tracking->action_id ) ) { 
  16. return false; 
  17.  
  18. // Set the $activity_comment_object 
  19. $activity_comment_object = $activity_post_object->comments_tracking; 
  20.  
  21. if ( empty( $activity_comment_object->action_id ) ) { 
  22. return false; 
  23.  
  24. $deleted = false; 
  25.  
  26. $deleted = bp_activity_delete_by_item_id( array( 
  27. 'item_id' => get_current_blog_id(),  
  28. 'secondary_item_id' => $comment_id,  
  29. 'component' => $activity_comment_object->component_id,  
  30. 'type' => $activity_comment_object->action_id,  
  31. 'user_id' => false,  
  32. ) ); 
  33.  
  34. /** 
  35. * Fires after the custom post type comment activity was removed. 
  36. * @since 2.5.0 
  37. * @param bool $deleted True if the activity was deleted false otherwise 
  38. * @param WP_Comment $comment Comment object. 
  39. * @param object $activity_post_object The post type tracking args object. 
  40. * @param string $value The post type comment activity type. 
  41. */ 
  42. do_action( 'bp_activity_post_type_remove_comment', $deleted, $comment_id, $activity_post_object, $activity_comment_object->action_id ); 
  43.  
  44. return $deleted;