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 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 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.


Top ↑

Parameters Parameters

$args

(array) (Required) Arguments passed from bp_parse_args() in bp_has_activities().


Top ↑

Return Return

(array) $args


Source 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;
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Used for any synced Post type comments, in wp-admin or front-end contexts.
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.