BuddyPress: Hide Administrators' Activity From the Stream
Keeps activity created by administrators (such as testing posts and profile edits) out of the public activity streams.
Opens WPIDE on
Code
if ( ! function_exists( 'buddypress' ) ) {
return;
}
add_filter( 'bp_after_has_activities_parse_args', function ( $args ) {
if ( bp_is_user() && bp_is_my_profile() ) {
return $args;
}
$admins = get_transient( 'wpide_bp_admin_ids' );
if ( false === $admins ) {
$admins = array_map( 'intval', get_users( array( 'role' => 'administrator', 'fields' => 'ID', 'number' => 200 ) ) );
set_transient( 'wpide_bp_admin_ids', $admins, HOUR_IN_SECONDS );
}
if ( $admins ) {
$query = empty( $args['filter_query'] ) ? array() : (array) $args['filter_query'];
$query[] = array( 'column' => 'user_id', 'value' => $admins, 'compare' => 'NOT IN' );
$args['filter_query'] = $query;
}
return $args;
} );
add_action( 'set_user_role', function () {
delete_transient( 'wpide_bp_admin_ids' );
} );
Notes
Administrators still see everything on their own profile. The ID list is cached for an hour.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.