bp_blogs_remove_activity_meta_for_trashed_comments

When a post is trashed, remove each comment's associated activity meta.

Description

bp_blogs_remove_activity_meta_for_trashed_comments( (int) $post_id = 0, (array) $comments = array() ); 

When a post is trashed and later untrashed, we currently don't reinstate activity items for these comments since their activity entries are already deleted when initially trashed.

Since these activity entries are deleted, we need to remove the deleted activity comment IDs from each comment's meta when a post is trashed.

Parameters (2)

0. $post_id — Optional. (int)
The post id.
1. $comments — Optional. (array) => array()
Array of comment statuses. The key is comment ID, the value is the $comment->comment_approved value.

Usage

  1. if ( !function_exists( 'bp_blogs_remove_activity_meta_for_trashed_comments' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-activity.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // Array of comment statuses. The key is comment ID, the 
  8. // value is the $comment->comment_approved value. 
  9. $comments = array(); 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bp_blogs_remove_activity_meta_for_trashed_comments($post_id, $comments); 
  13.  

Defined (1)

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

/bp-blogs/bp-blogs-activity.php  
  1. function bp_blogs_remove_activity_meta_for_trashed_comments( $post_id = 0, $comments = array() ) { 
  2. if ( ! empty( $comments ) ) { 
  3. foreach ( array_keys( $comments ) as $comment_id ) { 
  4. delete_comment_meta( $comment_id, 'bp_activity_comment_id' );