bp_blogs_update_post_activity_meta

Updates a blog post's activity meta entry during a post edit.

Description

bp_blogs_update_post_activity_meta( (WP_Post) $post, (BP_Activity_Activity) $activity, (object) $activity_post_object ); 

Parameters (3)

0. $post (WP_Post)
Post object.
1. $activity (BP_Activity_Activity)
Activity object.
2. $activity_post_object (object)
The post type tracking args object.

Usage

  1. if ( !function_exists( 'bp_blogs_update_post_activity_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-functions.php'; 
  3.  
  4. // Post object. 
  5. $post = null; 
  6.  
  7. // Activity object. 
  8. $activity = null; 
  9.  
  10. // The post type tracking args object. 
  11. $activity_post_object = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_blogs_update_post_activity_meta($post, $activity, $activity_post_object); 
  15.  

Defined (1)

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

/bp-blogs/bp-blogs-functions.php  
  1. function bp_blogs_update_post_activity_meta( $post, $activity, $activity_post_object ) { 
  2. if ( empty( $activity->id ) || empty( $activity_post_object->action_id ) ) { 
  3. return; 
  4.  
  5. // Update post title in activity meta. 
  6. $existing_title = bp_activity_get_meta( $activity->id, 'post_title' ); 
  7. if ( $post->post_title !== $existing_title ) { 
  8. bp_activity_update_meta( $activity->id, 'post_title', $post->post_title ); 
  9.  
  10. if ( ! empty( $activity_post_object->comments_tracking->action_id ) ) { 
  11. // Now update activity meta for post comments... sigh. 
  12. $comments = get_comments( array( 'post_id' => $post->ID ) ); 
  13.  
  14. if ( ! empty( $comments ) ) { 
  15. $activity_ids = array(); 
  16. $comment_ids = wp_list_pluck( $comments, 'comment_ID' ); 
  17.  
  18. // Set up activity args. 
  19. $args = array( 
  20. 'update_meta_cache' => false,  
  21. 'show_hidden' => true,  
  22. 'per_page' => 99999,  
  23. ); 
  24.  
  25. // Query for old-style "new_blog_comment" activity items. 
  26. $args['filter'] = array( 
  27. 'object' => $activity_post_object->comments_tracking->component_id,  
  28. 'action' => $activity_post_object->comments_tracking->action_id,  
  29. 'secondary_id' => implode( ', ', $comment_ids ),  
  30. ); 
  31.  
  32. $activities = bp_activity_get( $args ); 
  33. if ( ! empty( $activities['activities'] ) ) { 
  34. $activity_ids = (array) wp_list_pluck( $activities['activities'], 'id' ); 
  35.  
  36. // Query for activity comments connected to a blog post. 
  37. unset( $args['filter'] ); 
  38. $args['meta_query'] = array( array( 
  39. 'key' => 'bp_blogs_' . $post->post_type . '_comment_id',  
  40. 'value' => $comment_ids,  
  41. 'compare' => 'IN',  
  42. ) ); 
  43. $args['type'] = 'activity_comment'; 
  44. $args['display_comments'] = 'stream'; 
  45.  
  46. $activities = bp_activity_get( $args ); 
  47. if ( ! empty( $activities['activities'] ) ) { 
  48. $activity_ids = array_merge( $activity_ids, (array) wp_list_pluck( $activities['activities'], 'id' ) ); 
  49.  
  50. // Update activity meta for all found activity items. 
  51. if ( ! empty( $activity_ids ) ) { 
  52. foreach ( $activity_ids as $aid ) { 
  53. bp_activity_update_meta( $aid, 'post_title', $post->post_title ); 
  54.  
  55. unset( $activities, $activity_ids, $comment_ids, $comments ); 
  56.  
  57. // Add post comment status to activity meta if closed. 
  58. if( 'closed' == $post->comment_status ) { 
  59. bp_activity_update_meta( $activity->id, 'post_comment_status', $post->comment_status ); 
  60. } else { 
  61. bp_activity_delete_meta( $activity->id, 'post_comment_status' );