bp_blogs_remove_associated_blog_comments

Removes blog comments that are associated with activity comments.

Description

bp_blogs_remove_associated_blog_comments( (array) $activity_ids = array(), (bool) $force_delete = true ); 

Parameters (2)

0. $activity_ids — Optional. (array) => array()
The activity IDs to check association with blog comments.
1. $force_delete — Optional. (bool) => true
Whether to force delete the comments. If false, comments are trashed instead.

Usage

  1. if ( !function_exists( 'bp_blogs_remove_associated_blog_comments' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-functions.php'; 
  3.  
  4. // The activity IDs to check association with blog 
  5. // comments. 
  6. $activity_ids = array(); 
  7.  
  8. // Whether to force delete the comments. If false, 
  9. // comments are trashed instead. 
  10. $force_delete = true; 
  11.  
  12. // NOTICE! Understand what this does before running. 
  13. $result = bp_blogs_remove_associated_blog_comments($activity_ids, $force_delete); 
  14.  

Defined (1)

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

/bp-blogs/bp-blogs-functions.php  
  1. function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $force_delete = true ) { 
  2. // Query args. 
  3. $query_args = array( 
  4. 'meta_query' => array( 
  5. array( 
  6. 'key' => 'bp_activity_comment_id',  
  7. 'value' => implode( ', ', (array) $activity_ids ),  
  8. 'compare' => 'IN',  
  9. ); 
  10.  
  11. // Get comment. 
  12. $comment_query = new WP_Comment_Query; 
  13. $comments = $comment_query->query( $query_args ); 
  14.  
  15. // Found the corresponding comments 
  16. // let's delete them! 
  17. foreach ( $comments as $comment ) { 
  18. wp_delete_comment( $comment->comment_ID, $force_delete ); 
  19.  
  20. // If we're trashing the comment, remove the meta key as well. 
  21. if ( empty( $force_delete ) ) { 
  22. delete_comment_meta( $comment->comment_ID, 'bp_activity_comment_id' );