cron_schedules
Allows you to add a new time interval for Cron tasks (schedules).
When a Cron task is added, it is normally assigned an interval after which it repeats. WordPress provides only three intervals by default:
$schedules = array( 'hourly' => array( 'interval' => HOUR_IN_SECONDS, 'display' => __( 'Once Hourly' ) ), 'twicedaily' => array( 'interval' => 12 * HOUR_IN_SECONDS, 'display' => __( 'Twice Daily' ) ), 'daily' => array( 'interval' => DAY_IN_SECONDS, 'display' => __( 'Once Daily' ) ), );
This filter can extend the interval list with custom intervals that can then be used when creating a Cron task.
wp_schedule_event() explains in detail how to create custom tasks.
Usage
add_filter( 'cron_schedules', 'wp_kama_cron_schedules_filter' );
/**
* Function for `cron_schedules` filter-hook.
*
* @param array $new_schedules An array of non-default cron schedules keyed by the schedule name.
*
* @return array
*/
function wp_kama_cron_schedules_filter( $new_schedules ){
// filter...
return $new_schedules;
}
- $new_schedules(array)
- An array containing new time interval data.
Default: array()
Examples
#1 Add a new Cron interval
Add an event interval of once every 5 minutes:
// Register a five-minute interval
add_filter( 'cron_schedules', 'cron_add_five_min' );
function cron_add_five_min( $schedules ) {
$schedules['five_min'] = array(
'interval' => 60 * 5,
'display' => 'Once every 5 minutes'
);
return $schedules;
}Changelog
| Since 2.1.0 | Introduced. |
Where the hook is called
cron_schedules
wp-includes/cron.php 1169
return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );