bp_blogs_sync_delete_from_activity_comment

Deletes the blog comment when the associated activity comment is deleted.

Description

bp_blogs_sync_delete_from_activity_comment( (bool) $retval, (int) $parent_activity_id, (int) $activity_id, (bool) &$deleted ); 

Note: This is hooked on the bp_activity_delete_comment_pre filter instead of the bp_activity_delete_comment action because we need to fetch the activity comment children before they are deleted.

Parameters (4)

0. $retval (bool)
Whether BuddyPress should continue or not.
1. $parent_activity_id (int)
The parent activity ID for the activity comment.
2. $activity_id (int)
The activity ID for the pending deleted activity comment.
3. $deleted (bool) => &$deleted
Whether the comment was deleted or not.

Usage

  1. if ( !function_exists( 'bp_blogs_sync_delete_from_activity_comment' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-activity.php'; 
  3.  
  4. // Whether BuddyPress should continue or not. 
  5. $retval = true; 
  6.  
  7. // The parent activity ID for the activity comment. 
  8. $parent_activity_id = -1; 
  9.  
  10. // The activity ID for the pending deleted activity comment. 
  11. $activity_id = -1; 
  12.  
  13. // Whether the comment was deleted or not. 
  14. $deleted = &$deleted; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bp_blogs_sync_delete_from_activity_comment($retval, $parent_activity_id, $activity_id, $deleted); 
  18.  

Defined (1)

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

/bp-blogs/bp-blogs-activity.php  
  1. function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id, &$deleted ) { 
  2. // Check if parent activity is a blog post. 
  3. $parent_activity = new BP_Activity_Activity( $parent_activity_id ); 
  4.  
  5. // if parent activity isn't a post type having the buddypress-activity support, stop now! 
  6. if ( ! bp_activity_type_supports( $parent_activity->type, 'post-type-comment-tracking' ) ) { 
  7. return $retval; 
  8.  
  9. // Fetch the activity comments for the activity item. 
  10. $activity = bp_activity_get( array( 
  11. 'in' => $activity_id,  
  12. 'display_comments' => 'stream',  
  13. 'spam' => 'all',  
  14. ) ); 
  15.  
  16. // Get all activity comment IDs for the pending deleted item. 
  17. $activity_ids = bp_activity_recurse_comments_activity_ids( $activity ); 
  18. $activity_ids[] = $activity_id; 
  19.  
  20. // Handle multisite 
  21. // switch to the blog where the comment was made. 
  22. switch_to_blog( $parent_activity->item_id ); 
  23.  
  24. // Remove associated blog comments. 
  25. bp_blogs_remove_associated_blog_comments( $activity_ids, current_user_can( 'moderate_comments' ) ); 
  26.  
  27. // Multisite again! 
  28.  
  29. // Rebuild activity comment tree 
  30. BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id ); 
  31.  
  32. // Avoid theerrormessage although the comments were successfully deleted 
  33. $deleted = true; 
  34.  
  35. // We're overriding the default bp_activity_delete_comment() functionality 
  36. // so we need to return false. 
  37. return false;