wp_get_schedules

Retrieve supported event recurrence schedules.

Description

(array) wp_get_schedules(); 

The default supported recurrences are hourly,, twicedaily., and daily. A plugin may add more by hooking into the 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.

interval => 604800,

Returns (array)


Usage

  1. if ( !function_exists( 'wp_get_schedules' ) ) { 
  2. require_once ABSPATH . WPINC . '/cron.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_get_schedules(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/cron.php  
  1. function wp_get_schedules() { 
  2. $schedules = array( 
  3. 'hourly' => array( 'interval' => HOUR_IN_SECONDS, 'display' => __( 'Once Hourly' ) ),  
  4. 'twicedaily' => array( 'interval' => 12 * HOUR_IN_SECONDS, 'display' => __( 'Twice Daily' ) ),  
  5. 'daily' => array( 'interval' => DAY_IN_SECONDS, 'display' => __( 'Once Daily' ) ),  
  6. ); 
  7. /** 
  8. * Filters the non-default cron schedules. 
  9. * @since 2.1.0 
  10. * @param array $new_schedules An array of non-default cron schedules. Default empty. 
  11. */ 
  12. return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );