bp_blogs_new_blog_comment_query_backpat( array $args )
Filter ‘new_blog_comment’ bp_has_activities() loop to include new- and old-style blog activity comment items.
Description
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 feed 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.
Parameters
- $args
-
(Required) Arguments passed from bp_parse_args() in bp_has_activities().
Return
(array) $args
Source
File: bp-blogs/bp-blogs-activity.php
function bp_blogs_new_blog_comment_query_backpat( $args ) {
global $wpdb;
$bp = buddypress();
// If activity comments are disabled for blog posts, stop now!
if ( bp_disable_blogforum_comments() ) {
return $args;
}
// Get the associated post type
$post_type = bp_activity_post_type_get_tracking_arg( $args['action'], 'post_type' );
// Bail if this is not an activity associated with a post type
if ( empty( $post_type ) ) {
return $args;
}
// Bail if this is an activity about posts and not comments
if ( bp_activity_post_type_get_tracking_arg( $args['action'], 'comment_action_id' ) ) {
return $args;
}
// Comment synced ?
$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" ) );
if ( empty( $activity_ids ) ) {
return $args;
}
// Init the filter query.
$filter_query = array();
if ( ! isset( $args['scope'] ) || 'null' === $args['scope'] ) {
$args['scope'] = '';
} elseif ( 'just-me' === $args['scope'] ) {
$filter_query = array(
'relation' => 'AND',
array(
'column' => 'user_id',
'value' => bp_displayed_user_id(),
),
);
$args['scope'] = '';
}
$filter_query[] = array(
'relation' => 'OR',
array(
'column' => 'type',
'value' => $args['action'],
),
array(
'column' => 'id',
'value' => $activity_ids,
'compare' => 'IN'
),
);
$args['filter_query'] = $filter_query;
// Make sure to have comment in stream mode && avoid duplicate content.
$args['display_comments'] = 'stream';
// Finally reset the action.
$args['action'] = '';
$args['type'] = '';
// Return the original arguments.
return $args;
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 2.5.0 Used for any synced Post type comments, in wp-admin or front-end contexts. | BuddyPress 2.5.0 Used for any synced Post type comments, in wp-admin or front-end contexts. |
| BuddyPress 2.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.