Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: @mentions show up on personal activity streams like they do here on BP.org?


Boone Gorges
Keymaster

@boonebgorges

Here’s how buddypress.org does it, with a filter that essentially adds a search term ‘ @username‘ to the bp_has_activities filter:
`function bporg_activity_with_others_filter( $qs ) {
global $bp;

$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();

/* Only filter on directory pages (no action) and the following scope on activity object. */
if ( ( ‘dashboard’ == $bp->current_action && strpos( $qs, ‘personal’ ) !== false ) || ‘just-me’ == $bp->current_action ) {
if ( strpos( $qs, ‘filter’ ) === false )
$qs .= ‘&search_terms=@’ . bp_core_get_username( $user_id ) . ‘<';

return $qs;
} else {
return $qs;
}
}
add_filter( ‘bp_ajax_querystring’, ‘bporg_activity_with_others_filter’, 11 );`

The problem with this approach is that the search bypasses the private/hidden group setting, so activity created inside of a group will show up on public profile pages if it contains @username in it. Here’s a filter that gets around it about halfway, in a hackish way:
`function bporg_ensure_hidden_activity_updates( $has_activities ) {
global $activities_template, $bp;

if ( bp_is_my_profile() || !$bp->displayed_user->id )
return $has_activities;

foreach( $activities_template->activities as $a_key => $a ) {
if ( $a->type != ‘activity_update’ && $a->type != ‘activity_comment’ )
continue;

if ( $a->component != ‘groups’ )
continue;

$group = new BP_Groups_Group( $a->item_id );

if ( $group->status != ‘public’ ) {
unset( $activities_template->activities[$a_key] );
$activities_template->total_activity_count = $activities_template->total_activity_count – 1;
$activities_template->activity_count = $activities_template->activity_count – 1;
}

$activities_template->activities = array_values( $activities_template->activities );
}

return $has_activities;
}
add_filter( ‘bp_has_activities’, ‘bporg_ensure_hidden_activity_updates’, 999 );`

This latter problem should be fixed in BP 1.3.

Skip to toolbar