Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is there a way to suppress group membership activities in group activity feeds?


  • jreeve
    Participant

    @jreeve

    My groups have a lot of membership changes, and this makes the activity feed very noisy. Is there a way to suppress group membership activities (members joining groups, members leaving groups) from appearing in the activity feeds for groups? If not, what would be the best way to go about writing a plugin to do this?

Viewing 3 replies - 1 through 3 (of 3 total)

  • shanebp
    Moderator

    @shanebp

    Unfortunately, there don’t seem to be hooks to avoid recording such activity.

    And unfortunately you can’t suppress the display of only some group activity stream items – it’s groups or no groups.

    So you have to filter all activity stream items – they all use the same code.

    Take a look at the filter hook at the bottom of
    function bp_has_activities
    in
    buddypress\bp-activity\bp-activity-template.php

    This thread should give you some code to start with:
    https://buddypress.org/support/topic/is-it-possible-to-hide-or-remove-activity-in-the-main-activity-stream-from-certain-groups-while-keep/


    jreeve
    Participant

    @jreeve

    I can sort of do what I want by putting this a plugin:

    function filter_out_membership_activities($a, $activities, $args){ 
    	$args[per_page] = 9999; //We have to edit the full list, otherwise we'd just be editing the first 20 items 
    	global $activities_template; 
    	$activities_template = new BP_Activity_Template($args); //rebuild activities based on new args
    	$i=0; 
    	foreach ($activities_template->activities as $activity) { 
    		if ($activity->type == 'joined_group') { 
    			unset($activities_template->activities[$i]); //get rid of membership activity items
    			$activities_template->activity_count = $activities_template->activity_count - 1; //change the count to reflect this 
    			$activities_template->total_activity_count = $activities_template->total_activity_count - 1; 
    		} 
    		$i = $i + 1; 
    	} 
    	$activities = $activities_template; 
            error_log(print_r($activities)); 
    	return array($a, $activites, $args);
    }
    
    add_filter('bp_has_activities', 'mla_filter_out_membership_activities', 10, 3); 

    The print_r($activities) shows the correct activities list, but that isn’t reflected in the actual activities displayed. I think I’m missing something here about how filters work, how parameters are being passed through them, and which ones get edited. What am I doing wrong?


    shanebp
    Moderator

    @shanebp

    It helps to turn on debugging in wp-config.php

    define('WP_DEBUG', true);

    add_filter('bp_has_activities', 'mla_filter_out_membership_activities', 10, 3);
    should be
    add_filter('bp_has_activities', 'filter_out_membership_activities', 10, 3);

    $args[per_page] should be $args[‘per_page’]

    return array($a, $activites, $args);
    should be
    return array($a, $activities, $args);

    minor:
    $i = $i + 1;
    should be
    ++$i;

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Is there a way to suppress group membership activities in group activity feeds?’ is closed to new replies.
Skip to toolbar