Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Support: Creating & Extending

Existing and new plugins/components and themes.

@mentions show up on personal activity streams like they do here on BP.org? (7 posts)

Started 1 year, 7 months ago by: bplove

  • Profile picture of bplove bplove said 1 year, 7 months ago:

    Is there a setting or an easy hack to get @mentions to show up on personal activity like they do here on bp.org? It doesn’t happen this way on my install, just shows the user activity and you have to click @mentions to see their @mentions. I like it better together. Tips?

  • Profile picture of Marc R. Marc R. said 1 year, 7 months ago:

    @bplove please share if you find a way to do it, I’m looking forward to do it too

  • Profile picture of Roger Coathup Roger Coathup said 1 year, 7 months ago:

    @bplove @marcrem

    You’ll need to build your own bespoke theme, with a custom activity loop that doesn’t filter ‘the scope’, but instead shows all activities.

    Sounds confusing – unfortunately, it is a little.

    The default BuddyPress theme uses a set of filters (put together by a javascript routine in _inc/ajax.php) to determine which entries to show when you visit someone’s activity.

    You can read more about building your own theme, and on writing a custom activity loop in the docs section of this site.

  • Profile picture of Matt Cox Matt Cox said 1 year, 6 months ago:

    For the benefit of anyone else attempting to implement this, the above post is incorrect. Buddypress implemented @mention listing by searching the text of all activity updates. The function to query for activity (BP_Activity_Activity:get) allows you to query by user id AND search term, but not user id OR search term, as this feature requires.

    The only way I was able to get this working was by hacking bp-activity-classes.php, and updating the user_id sql in the get_filter_sql function. The updated code is as follows:

    if ( !empty( $filter_array['user_id'] ) ) {
    	$user_filter = explode( ',', $filter_array['user_id'] );
    	$user_sql = " ( a.user_id IN ( " . $filter_array['user_id'] . " ) ";
    	foreach ( $user_filter as $user_id ) {
    		$search_terms = '@' . bp_core_get_username( $user_id ) . '<';
    		$user_sql .= "OR ( a.content LIKE '%%".like_escape($search_terms)."%%' ) ";
    	}
    	$user_sql .= " ) ";
    	$filter_sql[] = $user_sql;
    }

    If someone has a more elegant solution, please let me know!

  • Profile picture of Boone Gorges Boone Gorges said 1 year, 6 months ago:

    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.

  • Profile picture of luvs luvs said 1 year, 4 months ago:

    does not work for me boone

  • Profile picture of gavinwrong gavinwrong said 1 year ago:

    @mattamatic you rock man, your code worked perfect for me here (something i’m doing for a client)… http://www.deconstruct3d.com/aampp. THANKS!