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.
This guide explains how to use the wp_statistics_cron_schedules
filter to modify the predefined cron schedules used in the WP Statistics plugin. By leveraging this filter, you can customize the intervals, display names, start and end dates, and next schedule times of the cron jobs.
wp_statistics_cron_schedules
FilterThe wp_statistics_cron_schedules
filter allows developers to adjust the predefined scheduling intervals for WP Statistics. This filter is applied to the array of schedules generated by the getSchedules
method.
apply_filters('wp_statistics_cron_schedules', $schedules);
$schedules
(array): An associative array of predefined schedules. Each schedule includes:interval
(int): The interval in seconds between each scheduled event.display
(string): The display name of the schedule.start
(string): The start date of the schedule period in ‘Y-m-d’ format.end
(string): The end date of the schedule period in ‘Y-m-d’ format.next_schedule
(int): The Unix timestamp for the next scheduled occurrence.The default schedules passed to the filter are:
Daily Schedule
DAY_IN_SECONDS
(24 hours).Weekly Schedule
WEEK_IN_SECONDS
(7 days).Bi-Weekly Schedule
2 * WEEK_IN_SECONDS
(14 days).Monthly Schedule
MONTH_IN_SECONDS
.To modify the existing schedules or add a new custom schedule, hook into the wp_statistics_cron_schedules
filter in your theme or plugin:
add_filter('wp_statistics_cron_schedules', 'custom_wp_statistics_cron_schedules');
function custom_wp_statistics_cron_schedules($schedules) {
// Example of modifying the daily schedule interval
$schedules['daily']['interval'] = 12 * HOUR_IN_SECONDS; // Every 12 hours
$schedules['daily']['display'] = __('Twice Daily', 'your-text-domain');
// Example of adding a custom schedule
$schedules['hourly'] = [
'interval' => HOUR_IN_SECONDS,
'display' => __('Hourly', 'your-text-domain'),
'start' => wp_date('Y-m-d', strtotime("-1 hour")),
'end' => wp_date('Y-m-d'),
'next_schedule' => strtotime('+1 hour')
];
return $schedules;
}
In this example:
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.