Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Excluding blog post comments from activity stream page?


Boone Gorges
Keymaster

@boonebgorges

You can filter the activity stream on a certain page with something like this:

function bp_no_blog_comment_filter( $a, $activities ) {
global $bp;

/* Only run the filter on activity streams where you want blog comments filtered out. For example, the following will only filter them on the sitewide activity tab: */
if ( $bp->current_component != $bp->activity->slug )
return $activities;

/* Then filter out all the blog comments */
foreach( $activities->activities as $key => $activity ) {
if ( $activity->type == 'new_blog_comment' ) {
unset( $activities->activities[$key] );
$activities->total_activity_count = $activities->total_activity_count - 1;
$activities->activity_count = $activities->activity_count - 1;
}
}

/* Renumber the array keys to account for missing items */
$activities_new = array_values( $activities->activities );
$activities->activities = $activities_new;
return $activities;
}
add_action( 'bp_has_activities', 'bp_no_blog_comment_filter', 10, 2 );

Obviously you may want to tweak some of the details, but that’s the basic idea – the comments are still recorded to the stream, and still appear on the individual member streams.

Skip to toolbar