Customizing Cron Schedules

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.

Applying the wp_statistics_cron_schedules Filter

Purpose

The 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.

Hook Syntax

apply_filters('wp_statistics_cron_schedules', $schedules);

Parameters

Default Schedules

The default schedules passed to the filter are:

Daily Schedule

    Weekly Schedule

      Bi-Weekly Schedule

        Monthly Schedule

          Example Usage

          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:

          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.