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

1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
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

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.