bp_blogs_sync_activity_edit_to_post_comment

Updates the blog comment when the associated activity comment is edited.

Description

bp_blogs_sync_activity_edit_to_post_comment( (BP_Activity_Activity) BP_Activity_Activity $activity ); 

Parameters (1)

0. $activity (BP_Activity_Activity) => BP_Activity_Activity $activity
The activity object.

Usage

  1. if ( !function_exists( 'bp_blogs_sync_activity_edit_to_post_comment' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-activity.php'; 
  3.  
  4. // The activity object. 
  5. $activity = BP_Activity_Activity $activity; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_blogs_sync_activity_edit_to_post_comment($activity); 
  9.  

Defined (1)

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

/bp-blogs/bp-blogs-activity.php  
  1. function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) { 
  2. // This is a new entry, so stop! 
  3. // We only want edits! 
  4. if ( empty( $activity->id ) || bp_disable_blogforum_comments() ) { 
  5. return; 
  6.  
  7. // fetch parent activity item 
  8. $parent_activity = new BP_Activity_Activity( $activity->item_id ); 
  9.  
  10. // if parent activity isn't a post type having the buddypress-activity support for comments, stop now! 
  11. if ( ! bp_activity_type_supports( $parent_activity->type, 'post-type-comment-tracking' ) ) { 
  12. return; 
  13.  
  14. $post_type = bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'post_type' ); 
  15.  
  16. // No associated post type for this activity comment, stop. 
  17. if ( ! $post_type ) { 
  18. return; 
  19.  
  20. // Try to see if a corresponding blog comment exists. 
  21. $post_comment_id = bp_activity_get_meta( $activity->id, "bp_blogs_{$post_type}_comment_id" ); 
  22.  
  23. if ( empty( $post_comment_id ) ) { 
  24. return; 
  25.  
  26. // Handle multisite. 
  27. switch_to_blog( $parent_activity->item_id ); 
  28.  
  29. // Get the comment status 
  30. $post_comment_status = wp_get_comment_status( $post_comment_id ); 
  31. $old_comment_status = $post_comment_status; 
  32.  
  33. // No need to edit the activity, as it's the activity who's updating the comment 
  34.  
  35. if ( 1 === $activity->is_spam && 'spam' !== $post_comment_status ) { 
  36. wp_spam_comment( $post_comment_id ); 
  37. } elseif ( ! $activity->is_spam ) { 
  38. if ( 'spam' === $post_comment_status ) { 
  39. wp_unspam_comment( $post_comment_id ); 
  40. } elseif ( 'trash' === $post_comment_status ) { 
  41. wp_untrash_comment( $post_comment_id ); 
  42. } else { 
  43. // Update the blog post comment. 
  44. wp_update_comment( array( 
  45. 'comment_ID' => $post_comment_id,  
  46. 'comment_content' => $activity->content,  
  47. ) ); 
  48.  
  49. // Restore actions 
  50.