Hooks & Filters Reference

Get Started

Hooks & Filters Reference

This document lists all action hooks and filters available in BuddyPress Stats for customization and extension.

Filter Hooks

Core Settings

bp_stats_general_default_settings

Modify the default plugin settings.

add_filter( 'bp_stats_general_default_settings', function( $defaults ) {
    $defaults['show_member_stats'] = 'no';
    return $defaults;
});

Parameters: $defaults (array) – Default settings array

bp_stats_can_view_user_stats

Control who can view user statistics.

add_filter( 'bp_stats_can_view_user_stats', function( $can_view, $user_id ) {
    // Allow users to view their own stats
    if ( get_current_user_id() === $user_id ) {
        return true;
    }
    // Allow admins to view all stats
    if ( current_user_can( 'manage_options' ) ) {
        return true;
    }
    return $can_view;
}, 10, 2 );

Parameters: $can_view (bool) – Default: false, $user_id (int) – User ID being viewed

bp_stats_get_user_ip

Filter the IP address before storing. Useful for GDPR anonymization.

add_filter( 'bp_stats_get_user_ip', function( $ip ) {
    // Anonymize last octet
    return preg_replace( '/\.\d+$/', '.0', $ip );
});

Profile and Group Tabs

bp_stats_statistics_label

Change the label for the Statistics tab on member profiles. Default: “Statistics”

bp_stats_statistics_slug

Change the URL slug for the Statistics tab. Default: “statistics”

bp_stats_profile_statistics_tab_filter

Change the position of the Statistics tab on member profiles. Default: 80

bp_stats_show_group_stats_tab

Control whether the group statistics tab appears based on group ID or other conditions.

bp_stats_group_statistics_tab_filter

Change the position of the Statistics tab on group pages. Default: 80

Activity Tracking

bp_stats_activity_types_insert

Filter which activity types are tracked when activities are created. Default: ['activity_update', 'activity_comment', 'activity_status']

bp_stats_max_top_contributors

Set the maximum number of top contributors to display. Default: 10

User Information Limits

bp_stats_user_friends_limit

Control friends display limit in user panels. Default: 5

bp_stats_user_activity_update_limit

Control activity display limit in user panels. Default: 5

bp_stats_user_join_group_limit

Control groups display limit in user panels. Default: 5

Data Management

bp_stats_days_to_keep_logs

Control how many days of logs to retain. Default: 90

bp_stats_clean_logs_on_deactivate

Whether to delete logs when the plugin is deactivated. Default: false

Activity Log Display

bp_stats_topic_colors

Customize the colors used for activity topic badges.

bp_stats_format_ip_address

Filter IP address before display in activity log.

Action Hooks

Activity Log Processing

bp_stats_before_format_activity_log

Fires before an activity log entry is formatted.

bp_stats_after_format_activity_log

Fires after an activity log entry is formatted.

Cache Events

bp_stats_cache_warmed

Fires after cache warming completes.

Usage Examples

Restrict Stats to Logged-in Users Only

add_filter( 'bp_stats_can_view_user_stats', function( $can_view, $user_id ) {
    return is_user_logged_in();
}, 10, 2 );

GDPR-Compliant IP Logging

add_filter( 'bp_stats_get_user_ip', function( $ip ) {
    // Remove last two octets
    return preg_replace( '/\.\d+\.\d+$/', '.0.0', $ip );
});

Move Statistics Tab to First Position

add_filter( 'bp_stats_profile_statistics_tab_filter', function() {
    return 10;
});

Extend Log Retention

add_filter( 'bp_stats_days_to_keep_logs', function() {
    return 365; // Keep one year of logs
});
Last updated: January 28, 2026