BuddyPress Block Activity Types
• 2 min read
buddpress wordpress php
BuddyPress saves a bunch of activity in the feed. For example it adds an activity item for every new user, user updates profile, users become friends and many more. It can be overwhelming if the site has alotof activity. Another reason to block is the database can fill up really fast.
This code is an example how you can filter out what gets saved.
function modemlooper_activity_dont_save( $activity_object ) {
$exclude = array(
'joined_group',
'activity_update',
'new_member',
'created_group',
'updated_profile',
'new_avatar',
'new_event',
'friendship_accepted',
'friendship_created',
'new_blog_comment',
'new_blog_post',
);
// If the activity type is empty, it stops BuddyPress BP_Activity_Activity::save() function.
if ( in_array( $activity_object->type, $exclude, true ) ) {
$activity_object->type = false;
}
}
add_action( 'bp_activity_before_save', 'modemlooper_activity_dont_save', 10, 1 );
function modemlooper_filter_activity_show_filters( $filters, $context ) {
$excludes = array(
'joined_group',
'group_details_updated',
'activity_update',
'updated_profile',
'joined_group',
'new_member',
'created_group',
'friendship_accepted,friendship_created',
'new_blog_comment',
'new_blog_post',
);
foreach ( $excludes as $exclude ) {
unset( $filters[ $exclude ] );
}
return $filters;
}
add_filter( 'bp_get_activity_show_filters_options', 'modemlooper_filter_activity_show_filters', 10, 2 );