bp_blogs_new_blog_comment_query_backpat

Filter 'new_blog_comment' bp_has_activities() loop to include new- and old-style blog activity comment items.

Description

(array) bp_blogs_new_blog_comment_query_backpat( (array) $args ); 

In BuddyPress 2.0, the schema for storing activity items related to blog posts changed. Instead creating new top-level new_blog_comment activity items, blog comments are recorded in the activity stream as comments on the 'new_blog_post' activity items corresponding to the parent post. This filter ensures that the new_blog_comment filter in bp_has_activities() (which powers the Comments filter in the activity directory dropdown) includes both old-style and new-style activity comments.

Returns (array)

$args

Parameters (1)

0. $args (array)
Arguments passed from bp_parse_args() in bp_has_activities().

Usage

  1. if ( !function_exists( 'bp_blogs_new_blog_comment_query_backpat' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-activity.php'; 
  3.  
  4. // Arguments passed from bp_parse_args() in bp_has_activities(). 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_blogs_new_blog_comment_query_backpat($args); 
  9.  

Defined (1)

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

/bp-blogs/bp-blogs-activity.php  
  1. function bp_blogs_new_blog_comment_query_backpat( $args ) { 
  2. global $wpdb; 
  3. $bp =buddypress); 
  4.  
  5. // If activity comments are disabled for blog posts, stop now! 
  6. return $args; 
  7.  
  8. // Get the associated post type 
  9. $post_type = bp_activity_post_type_get_tracking_arg( $args['action'], 'post_type' ); 
  10.  
  11. // Bail if this is not an activity associated with a post type 
  12. if ( empty( $post_type ) ) { 
  13. return $args; 
  14.  
  15. // Bail if this is an activity about posts and not comments 
  16. if ( bp_activity_post_type_get_tracking_arg( $args['action'], 'comment_action_id' ) ) { 
  17. return $args; 
  18.  
  19. // Comment synced ? 
  20. $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE meta_key = %s", "bp_blogs_{$post_type}_comment_id" ) ); 
  21.  
  22. if ( empty( $activity_ids ) ) { 
  23. return $args; 
  24.  
  25. // Init the filter query. 
  26. $filter_query = array(); 
  27.  
  28. if ( ! isset( $args['scope'] ) || 'null' === $args['scope'] ) { 
  29. $args['scope'] = ''; 
  30. } elseif ( 'just-me' === $args['scope'] ) { 
  31. $filter_query = array( 
  32. 'relation' => 'AND',  
  33. array( 
  34. 'column' => 'user_id',  
  35. 'value' => bp_displayed_user_id(),  
  36. ),  
  37. ); 
  38. $args['scope'] = ''; 
  39.  
  40. $filter_query[] = array( 
  41. 'relation' => 'OR',  
  42. array( 
  43. 'column' => 'type',  
  44. 'value' => $args['action'],  
  45. ),  
  46. array( 
  47. 'column' => 'id',  
  48. 'value' => $activity_ids,  
  49. 'compare' => 'IN' 
  50. ),  
  51. ); 
  52.  
  53. $args['filter_query'] = $filter_query; 
  54.  
  55. // Make sure to have comment in stream mode && avoid duplicate content. 
  56. $args['display_comments'] = 'stream'; 
  57.  
  58. // Finally reset the action. 
  59. $args['action'] = ''; 
  60. $args['type'] = ''; 
  61.  
  62. // Return the original arguments. 
  63. return $args;