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/
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?
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;