wp_get_schedules()

Retrieve supported event recurrence schedules.


Description Description

The default supported recurrences are ‘hourly’, ‘twicedaily’, and ‘daily’. A plugin may add more by hooking into the ‘cron_schedules’ filter. The filter accepts an array of arrays. The outer array has a key that is the name of the schedule or for example ‘weekly’. The value is an array with two keys, one is ‘interval’ and the other is ‘display’.

The ‘interval’ is a number in seconds of when the cron job should run. So for ‘hourly’, the time is 3600 or 60_60. For weekly, the value would be 60_60_24_7 or 604800. The value of ‘interval’ would then be 604800.

The ‘display’ is the description. For the ‘weekly’ key, the ‘display’ would be __( 'Once Weekly' ).

For your plugin, you will be passed an array. you can easily add your schedule by doing the following.

// Filter parameter variable name is 'array'.
$array['weekly'] = array(
    'interval' => 604800,
       'display'  => __( 'Once Weekly' )
);

Return Return

(array)


Top ↑

Source Source

File: wp-includes/cron.php

function wp_get_schedules() {
	$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' ) ),
	);
	/**
	 * Filters the non-default cron schedules.
	 *
	 * @since 2.1.0
	 *
	 * @param array $new_schedules An array of non-default cron schedules. Default empty.
	 */
	return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex

    Basic Example
    The ‘display’ is the description. For the ‘weekly’ key, the ‘display’ would be

    __( 'Once Weekly' );
    

    For your plugin, you will be passed an array. You can easily add a new interval schedule by doing the following using the ‘cron_schedules’ filter.

     add_filter( 'cron_schedules', 'cron_add_weekly' );
     
     function cron_add_weekly( $schedules ) {
     	// Adds once weekly to the existing schedules.
     	$schedules['weekly'] = array(
     		'interval' => 604800,
     		'display' => __( 'Once Weekly' )
     	);
     	return $schedules;
     }
    

You must log in before being able to contribute a note or feedback.