Customizing User Online Status Intervals

In this document, we introduce two new filters for customizing the behavior of the WP Statistics plugin: wp_statistics_reset_user_online_time for PHP and wp_statistics_js_check_time_interval for JavaScript.

1. wp_statistics_reset_user_online_time

The wp_statistics_reset_user_online_time filter allows you to customize the duration after which a user is considered offline in the WP Statistics plugin.

Usage

By default, the plugin uses a predefined duration to determine when a user is considered offline. This filter allows developers to modify this duration.

Applying the Filter

You can add the following code to your theme’s functions.php file or a custom plugin to change the reset time.

function custom_reset_user_online_time($reset_time) {
    // Set the reset time to 5 minutes (300 seconds)
    return 300;
}
add_filter('wp_statistics_reset_user_online_time', 'custom_reset_user_online_time');

In this example, the reset time is set to 300 seconds (5 minutes). You can adjust the duration as needed.

2. wp_statistics_js_check_time_interval

The wp_statistics_js_check_time_interval filter allows you to customize the interval at which the user’s online status is checked on the client side in JavaScript.

Usage

By default, the plugin checks the user’s online status every 60 seconds. This filter enables developers to modify this interval.

Applying the Filter

You can add the following code to your theme’s functions.php file or a custom plugin to change the JavaScript check time interval.

function custom_js_check_time_interval($check_time) {
    // Set the check time interval to 2 minutes (120000 milliseconds)
    return 120000;
}
add_filter('wp_statistics_js_check_time_interval', 'custom_js_check_time_interval');

In this example, the check time interval is set to 120000 milliseconds (2 minutes). You can adjust the interval as needed.

Let’s get started
Take your business to next level

Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.