wp/wp-includes/cron.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * WordPress CRON API
     3  * WordPress Cron API
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 /**
     8 /**
     9  * Schedules a hook to run only once.
     9  * Schedules an event to run only once.
    10  *
    10  *
    11  * Schedules a hook which will be executed once by the WordPress actions core at
    11  * Schedules an event which will execute once by the WordPress actions core at
    12  * a time which you specify. The action will fire off when someone visits your
    12  * a time which you specify. The action will fire off when someone visits your
    13  * WordPress site, if the schedule time has passed.
    13  * WordPress site, if the schedule time has passed.
    14  *
    14  *
       
    15  * Note that scheduling an event to occur within 10 minutes of an existing event
       
    16  * with the same action hook will be ignored unless you pass unique `$args` values
       
    17  * for each scheduled event.
       
    18  *
    15  * @since 2.1.0
    19  * @since 2.1.0
    16  * @link https://codex.wordpress.org/Function_Reference/wp_schedule_single_event
    20  * @link https://codex.wordpress.org/Function_Reference/wp_schedule_single_event
    17  *
    21  *
    18  * @param int $timestamp Timestamp for when to run the event.
    22  * @param int $timestamp Unix timestamp (UTC) for when to run the event.
    19  * @param string $hook Action hook to execute when cron is run.
    23  * @param string $hook Action hook to execute when event is run.
    20  * @param array $args Optional. Arguments to pass to the hook's callback function.
    24  * @param array $args Optional. Arguments to pass to the hook's callback function.
       
    25  * @return false|void False if the event does not get scheduled.
    21  */
    26  */
    22 function wp_schedule_single_event( $timestamp, $hook, $args = array()) {
    27 function wp_schedule_single_event( $timestamp, $hook, $args = array()) {
    23 	// don't schedule a duplicate if there's already an identical event due within 10 minutes of it
    28 	// Make sure timestamp is a positive integer
       
    29 	if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
       
    30 		return false;
       
    31 	}
       
    32 
       
    33 	// Don't schedule a duplicate if there's already an identical event due within 10 minutes of it
    24 	$next = wp_next_scheduled($hook, $args);
    34 	$next = wp_next_scheduled($hook, $args);
    25 	if ( $next && abs( $next - $timestamp ) <= 10 * MINUTE_IN_SECONDS ) {
    35 	if ( $next && abs( $next - $timestamp ) <= 10 * MINUTE_IN_SECONDS ) {
    26 		return;
    36 		return false;
    27 	}
    37 	}
    28 
    38 
    29 	$crons = _get_cron_array();
    39 	$crons = _get_cron_array();
    30 	$event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args );
    40 	$event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args );
    31 	/**
    41 	/**
    32 	 * Filter a single event before it is scheduled.
    42 	 * Filters a single event before it is scheduled.
    33 	 *
    43 	 *
    34 	 * @since 3.1.0
    44 	 * @since 3.1.0
    35 	 *
    45 	 *
    36 	 * @param object $event An object containing an event's data.
    46 	 * @param stdClass $event {
       
    47 	 *     An object containing an event's data.
       
    48 	 *
       
    49 	 *     @type string       $hook      Action hook to execute when event is run.
       
    50 	 *     @type int          $timestamp Unix timestamp (UTC) for when to run the event.
       
    51 	 *     @type string|false $schedule  How often the event should recur. See `wp_get_schedules()`.
       
    52 	 *     @type array        $args      Arguments to pass to the hook's callback function.
       
    53 	 * }
    37 	 */
    54 	 */
    38 	$event = apply_filters( 'schedule_event', $event );
    55 	$event = apply_filters( 'schedule_event', $event );
    39 
    56 
    40 	// A plugin disallowed this event
    57 	// A plugin disallowed this event
    41 	if ( ! $event )
    58 	if ( ! $event )
    47 	uksort( $crons, "strnatcasecmp" );
    64 	uksort( $crons, "strnatcasecmp" );
    48 	_set_cron_array( $crons );
    65 	_set_cron_array( $crons );
    49 }
    66 }
    50 
    67 
    51 /**
    68 /**
    52  * Schedule a periodic event.
    69  * Schedule a recurring event.
    53  *
    70  *
    54  * Schedules a hook which will be executed by the WordPress actions core on a
    71  * Schedules a hook which will be executed by the WordPress actions core on a
    55  * specific interval, specified by you. The action will trigger when someone
    72  * specific interval, specified by you. The action will trigger when someone
    56  * visits your WordPress site, if the scheduled time has passed.
    73  * visits your WordPress site, if the scheduled time has passed.
    57  *
    74  *
    58  * Valid values for the recurrence are hourly, daily and twicedaily. These can
    75  * Valid values for the recurrence are hourly, daily, and twicedaily. These can
    59  * be extended using the cron_schedules filter in wp_get_schedules().
    76  * be extended using the {@see 'cron_schedules'} filter in wp_get_schedules().
    60  *
    77  *
    61  * Use wp_next_scheduled() to prevent duplicates
    78  * Use wp_next_scheduled() to prevent duplicates
    62  *
    79  *
    63  * @since 2.1.0
    80  * @since 2.1.0
    64  *
    81  *
    65  * @param int $timestamp Timestamp for when to run the event.
    82  * @param int $timestamp Unix timestamp (UTC) for when to run the event.
    66  * @param string $recurrence How often the event should recur.
    83  * @param string $recurrence How often the event should recur.
    67  * @param string $hook Action hook to execute when cron is run.
    84  * @param string $hook Action hook to execute when event is run.
    68  * @param array $args Optional. Arguments to pass to the hook's callback function.
    85  * @param array $args Optional. Arguments to pass to the hook's callback function.
    69  * @return false|null False on failure, null when complete with scheduling event.
    86  * @return false|void False if the event does not get scheduled.
    70  */
    87  */
    71 function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) {
    88 function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) {
       
    89 	// Make sure timestamp is a positive integer
       
    90 	if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
       
    91 		return false;
       
    92 	}
       
    93 
    72 	$crons = _get_cron_array();
    94 	$crons = _get_cron_array();
    73 	$schedules = wp_get_schedules();
    95 	$schedules = wp_get_schedules();
    74 
    96 
    75 	if ( !isset( $schedules[$recurrence] ) )
    97 	if ( !isset( $schedules[$recurrence] ) )
    76 		return false;
    98 		return false;
    93 /**
   115 /**
    94  * Reschedule a recurring event.
   116  * Reschedule a recurring event.
    95  *
   117  *
    96  * @since 2.1.0
   118  * @since 2.1.0
    97  *
   119  *
    98  * @param int $timestamp Timestamp for when to run the event.
   120  * @param int $timestamp Unix timestamp (UTC) for when to run the event.
    99  * @param string $recurrence How often the event should recur.
   121  * @param string $recurrence How often the event should recur.
   100  * @param string $hook Action hook to execute when cron is run.
   122  * @param string $hook Action hook to execute when event is run.
   101  * @param array $args Optional. Arguments to pass to the hook's callback function.
   123  * @param array $args Optional. Arguments to pass to the hook's callback function.
   102  * @return false|null False on failure. Null when event is rescheduled.
   124  * @return false|void False if the event does not get rescheduled.
   103  */
   125  */
   104 function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
   126 function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
       
   127 	// Make sure timestamp is a positive integer
       
   128 	if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
       
   129 		return false;
       
   130 	}
       
   131 
   105 	$crons = _get_cron_array();
   132 	$crons = _get_cron_array();
   106 	$schedules = wp_get_schedules();
   133 	$schedules = wp_get_schedules();
   107 	$key = md5( serialize( $args ) );
   134 	$key = md5( serialize( $args ) );
   108 	$interval = 0;
   135 	$interval = 0;
   109 
   136 
   130 
   157 
   131 	wp_schedule_event( $timestamp, $recurrence, $hook, $args );
   158 	wp_schedule_event( $timestamp, $recurrence, $hook, $args );
   132 }
   159 }
   133 
   160 
   134 /**
   161 /**
   135  * Unschedule a previously scheduled cron job.
   162  * Unschedule a previously scheduled event.
   136  *
   163  *
   137  * The $timestamp and $hook parameters are required, so that the event can be
   164  * The $timestamp and $hook parameters are required so that the event can be
   138  * identified.
   165  * identified.
   139  *
   166  *
   140  * @since 2.1.0
   167  * @since 2.1.0
   141  *
   168  *
   142  * @param int $timestamp Timestamp for when to run the event.
   169  * @param int $timestamp Unix timestamp (UTC) for when to run the event.
   143  * @param string $hook Action hook, the execution of which will be unscheduled.
   170  * @param string $hook Action hook, the execution of which will be unscheduled.
   144  * @param array $args Arguments to pass to the hook's callback function.
   171  * @param array $args Arguments to pass to the hook's callback function.
   145  * Although not passed to a callback function, these arguments are used
   172  * Although not passed to a callback function, these arguments are used
   146  * to uniquely identify the scheduled event, so they should be the same
   173  * to uniquely identify the scheduled event, so they should be the same
   147  * as those used when originally scheduling the event.
   174  * as those used when originally scheduling the event.
       
   175  * @return false|void False if the event does not get unscheduled.
   148  */
   176  */
   149 function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
   177 function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
       
   178 	// Make sure timestamp is a positive integer
       
   179 	if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
       
   180 		return false;
       
   181 	}
       
   182 
   150 	$crons = _get_cron_array();
   183 	$crons = _get_cron_array();
   151 	$key = md5(serialize($args));
   184 	$key = md5(serialize($args));
   152 	unset( $crons[$timestamp][$hook][$key] );
   185 	unset( $crons[$timestamp][$hook][$key] );
   153 	if ( empty($crons[$timestamp][$hook]) )
   186 	if ( empty($crons[$timestamp][$hook]) )
   154 		unset( $crons[$timestamp][$hook] );
   187 		unset( $crons[$timestamp][$hook] );
   156 		unset( $crons[$timestamp] );
   189 		unset( $crons[$timestamp] );
   157 	_set_cron_array( $crons );
   190 	_set_cron_array( $crons );
   158 }
   191 }
   159 
   192 
   160 /**
   193 /**
   161  * Unschedule all cron jobs attached to a specific hook.
   194  * Unschedules all events attached to the hook with the specified arguments.
   162  *
   195  *
   163  * @since 2.1.0
   196  * @since 2.1.0
   164  *
   197  *
   165  * @param string $hook Action hook, the execution of which will be unscheduled.
   198  * @param string $hook Action hook, the execution of which will be unscheduled.
   166  * @param array $args Optional. Arguments that were to be pass to the hook's callback function.
   199  * @param array $args Optional. Arguments that were to be passed to the hook's callback function.
   167  */
   200  */
   168 function wp_clear_scheduled_hook( $hook, $args = array() ) {
   201 function wp_clear_scheduled_hook( $hook, $args = array() ) {
   169 	// Backward compatibility
   202 	// Backward compatibility
   170 	// Previously this function took the arguments as discrete vars rather than an array like the rest of the API
   203 	// Previously this function took the arguments as discrete vars rather than an array like the rest of the API
   171 	if ( !is_array($args) ) {
   204 	if ( !is_array($args) ) {
   172 		_deprecated_argument( __FUNCTION__, '3.0', __('This argument has changed to an array to match the behavior of the other cron functions.') );
   205 		_deprecated_argument( __FUNCTION__, '3.0.0', __('This argument has changed to an array to match the behavior of the other cron functions.') );
   173 		$args = array_slice( func_get_args(), 1 );
   206 		$args = array_slice( func_get_args(), 1 );
   174 	}
   207 	}
   175 
   208 
   176 	// This logic duplicates wp_next_scheduled()
   209 	// This logic duplicates wp_next_scheduled()
   177 	// It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing,
   210 	// It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing,
   187 		}
   220 		}
   188 	}
   221 	}
   189 }
   222 }
   190 
   223 
   191 /**
   224 /**
   192  * Retrieve the next timestamp for a cron event.
   225  * Unschedules all events attached to the hook.
   193  *
   226  *
   194  * @since 2.1.0
   227  * Can be useful for plugins when deactivating to clean up the cron queue.
   195  *
   228  *
   196  * @param string $hook Action hook to execute when cron is run.
   229  * @since 4.9.0
       
   230  *
       
   231  * @param string $hook Action hook, the execution of which will be unscheduled.
       
   232  */
       
   233 function wp_unschedule_hook( $hook ) {
       
   234 	$crons = _get_cron_array();
       
   235 
       
   236 	foreach( $crons as $timestamp => $args ) {
       
   237 		unset( $crons[ $timestamp ][ $hook ] );
       
   238 
       
   239 		if ( empty( $crons[ $timestamp ] ) ) {
       
   240 			unset( $crons[ $timestamp ] );
       
   241 		}
       
   242 	}
       
   243 
       
   244 	_set_cron_array( $crons );
       
   245 }
       
   246 
       
   247 /**
       
   248  * Retrieve the next timestamp for an event.
       
   249  *
       
   250  * @since 2.1.0
       
   251  *
       
   252  * @param string $hook Action hook to execute when event is run.
   197  * @param array $args Optional. Arguments to pass to the hook's callback function.
   253  * @param array $args Optional. Arguments to pass to the hook's callback function.
   198  * @return bool|int The UNIX timestamp of the next time the scheduled event will occur.
   254  * @return false|int The Unix timestamp of the next time the scheduled event will occur.
   199  */
   255  */
   200 function wp_next_scheduled( $hook, $args = array() ) {
   256 function wp_next_scheduled( $hook, $args = array() ) {
   201 	$crons = _get_cron_array();
   257 	$crons = _get_cron_array();
   202 	$key = md5(serialize($args));
   258 	$key = md5(serialize($args));
   203 	if ( empty($crons) )
   259 	if ( empty($crons) )
   208 	}
   264 	}
   209 	return false;
   265 	return false;
   210 }
   266 }
   211 
   267 
   212 /**
   268 /**
   213  * Send request to run cron through HTTP request that doesn't halt page loading.
   269  * Sends a request to run cron through HTTP request that doesn't halt page loading.
   214  *
   270  *
   215  * @since 2.1.0
   271  * @since 2.1.0
   216  *
   272  *
   217  * @return null Cron could not be spawned, because it is not needed to run.
   273  * @param int $gmt_time Optional. Unix timestamp (UTC). Default 0 (current time is used).
   218  */
   274  */
   219 function spawn_cron( $gmt_time = 0 ) {
   275 function spawn_cron( $gmt_time = 0 ) {
   220 
       
   221 	if ( ! $gmt_time )
   276 	if ( ! $gmt_time )
   222 		$gmt_time = microtime( true );
   277 		$gmt_time = microtime( true );
   223 
   278 
   224 	if ( defined('DOING_CRON') || isset($_GET['doing_wp_cron']) )
   279 	if ( defined('DOING_CRON') || isset($_GET['doing_wp_cron']) )
   225 		return;
   280 		return;
   226 
   281 
   227 	/*
   282 	/*
   228 	* multiple processes on multiple web servers can run this code concurrently
   283 	 * Get the cron lock, which is a Unix timestamp of when the last cron was spawned
   229 	* try to make this as atomic as possible by setting doing_cron switch
   284 	 * and has not finished running.
   230 	*/
   285 	 *
       
   286 	 * Multiple processes on multiple web servers can run this code concurrently,
       
   287 	 * this lock attempts to make spawning as atomic as possible.
       
   288 	 */
   231 	$lock = get_transient('doing_cron');
   289 	$lock = get_transient('doing_cron');
   232 
   290 
   233 	if ( $lock > $gmt_time + 10 * MINUTE_IN_SECONDS )
   291 	if ( $lock > $gmt_time + 10 * MINUTE_IN_SECONDS )
   234 		$lock = 0;
   292 		$lock = 0;
   235 
   293 
   245 	$keys = array_keys( $crons );
   303 	$keys = array_keys( $crons );
   246 	if ( isset($keys[0]) && $keys[0] > $gmt_time )
   304 	if ( isset($keys[0]) && $keys[0] > $gmt_time )
   247 		return;
   305 		return;
   248 
   306 
   249 	if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
   307 	if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
   250 		if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) ||  defined( 'XMLRPC_REQUEST' ) ) {
   308 		if ( 'GET' !== $_SERVER['REQUEST_METHOD'] || defined( 'DOING_AJAX' ) ||  defined( 'XMLRPC_REQUEST' ) ) {
   251 			return;
   309 			return;
   252 		}
   310 		}
   253 
   311 
   254 		$doing_wp_cron = sprintf( '%.22F', $gmt_time );
   312 		$doing_wp_cron = sprintf( '%.22F', $gmt_time );
   255 		set_transient( 'doing_cron', $doing_wp_cron );
   313 		set_transient( 'doing_cron', $doing_wp_cron );
   264 
   322 
   265 		WP_DEBUG ? include_once( ABSPATH . 'wp-cron.php' ) : @include_once( ABSPATH . 'wp-cron.php' );
   323 		WP_DEBUG ? include_once( ABSPATH . 'wp-cron.php' ) : @include_once( ABSPATH . 'wp-cron.php' );
   266 		return;
   324 		return;
   267 	}
   325 	}
   268 
   326 
       
   327 	// Set the cron lock with the current unix timestamp, when the cron is being spawned.
   269 	$doing_wp_cron = sprintf( '%.22F', $gmt_time );
   328 	$doing_wp_cron = sprintf( '%.22F', $gmt_time );
   270 	set_transient( 'doing_cron', $doing_wp_cron );
   329 	set_transient( 'doing_cron', $doing_wp_cron );
   271 
   330 
   272 	/**
   331 	/**
   273 	 * Filter the cron request arguments.
   332 	 * Filters the cron request arguments.
   274 	 *
   333 	 *
   275 	 * @since 3.5.0
   334 	 * @since 3.5.0
       
   335 	 * @since 4.5.0 The `$doing_wp_cron` parameter was added.
   276 	 *
   336 	 *
   277 	 * @param array $cron_request_array {
   337 	 * @param array $cron_request_array {
   278 	 *     An array of cron request URL arguments.
   338 	 *     An array of cron request URL arguments.
   279 	 *
   339 	 *
   280 	 *     @type string $url  The cron request URL.
   340 	 *     @type string $url  The cron request URL.
   285 	 *         @type int  $timeout   The request timeout in seconds. Default .01 seconds.
   345 	 *         @type int  $timeout   The request timeout in seconds. Default .01 seconds.
   286 	 *         @type bool $blocking  Whether to set blocking for the request. Default false.
   346 	 *         @type bool $blocking  Whether to set blocking for the request. Default false.
   287 	 *         @type bool $sslverify Whether SSL should be verified for the request. Default false.
   347 	 *         @type bool $sslverify Whether SSL should be verified for the request. Default false.
   288 	 *     }
   348 	 *     }
   289 	 * }
   349 	 * }
       
   350 	 * @param string $doing_wp_cron The unix timestamp of the cron lock.
   290 	 */
   351 	 */
   291 	$cron_request = apply_filters( 'cron_request', array(
   352 	$cron_request = apply_filters( 'cron_request', array(
   292 		'url'  => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ),
   353 		'url'  => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ),
   293 		'key'  => $doing_wp_cron,
   354 		'key'  => $doing_wp_cron,
   294 		'args' => array(
   355 		'args' => array(
   295 			'timeout'   => 0.01,
   356 			'timeout'   => 0.01,
   296 			'blocking'  => false,
   357 			'blocking'  => false,
   297 			/** This filter is documented in wp-includes/class-http.php */
   358 			/** This filter is documented in wp-includes/class-wp-http-streams.php */
   298 			'sslverify' => apply_filters( 'https_local_ssl_verify', false )
   359 			'sslverify' => apply_filters( 'https_local_ssl_verify', false )
   299 		)
   360 		)
   300 	) );
   361 	), $doing_wp_cron );
   301 
   362 
   302 	wp_remote_post( $cron_request['url'], $cron_request['args'] );
   363 	wp_remote_post( $cron_request['url'], $cron_request['args'] );
   303 }
   364 }
   304 
   365 
   305 /**
   366 /**
   306  * Run scheduled callbacks or spawn cron for all scheduled events.
   367  * Run scheduled callbacks or spawn cron for all scheduled events.
   307  *
   368  *
   308  * @since 2.1.0
   369  * @since 2.1.0
   309  *
       
   310  * @return null When doesn't need to run Cron.
       
   311  */
   370  */
   312 function wp_cron() {
   371 function wp_cron() {
   313 
       
   314 	// Prevent infinite loops caused by lack of wp-cron.php
   372 	// Prevent infinite loops caused by lack of wp-cron.php
   315 	if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) )
   373 	if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) )
   316 		return;
   374 		return;
   317 
   375 
   318 	if ( false === $crons = _get_cron_array() )
   376 	if ( false === $crons = _get_cron_array() )
   334 		}
   392 		}
   335 	}
   393 	}
   336 }
   394 }
   337 
   395 
   338 /**
   396 /**
   339  * Retrieve supported and filtered Cron recurrences.
   397  * Retrieve supported event recurrence schedules.
   340  *
   398  *
   341  * The supported recurrences are 'hourly' and 'daily'. A plugin may add more by
   399  * The default supported recurrences are 'hourly', 'twicedaily', and 'daily'. A plugin may
   342  * hooking into the 'cron_schedules' filter. The filter accepts an array of
   400  * add more by hooking into the {@see 'cron_schedules'} filter. The filter accepts an array
   343  * arrays. The outer array has a key that is the name of the schedule or for
   401  * of arrays. The outer array has a key that is the name of the schedule or for
   344  * example 'weekly'. The value is an array with two keys, one is 'interval' and
   402  * example 'weekly'. The value is an array with two keys, one is 'interval' and
   345  * the other is 'display'.
   403  * the other is 'display'.
   346  *
   404  *
   347  * The 'interval' is a number in seconds of when the cron job should run. So for
   405  * The 'interval' is a number in seconds of when the cron job should run. So for
   348  * 'hourly', the time is 3600 or 60*60. For weekly, the value would be
   406  * 'hourly', the time is 3600 or 60*60. For weekly, the value would be
   370 		'hourly'     => array( 'interval' => HOUR_IN_SECONDS,      'display' => __( 'Once Hourly' ) ),
   428 		'hourly'     => array( 'interval' => HOUR_IN_SECONDS,      'display' => __( 'Once Hourly' ) ),
   371 		'twicedaily' => array( 'interval' => 12 * HOUR_IN_SECONDS, 'display' => __( 'Twice Daily' ) ),
   429 		'twicedaily' => array( 'interval' => 12 * HOUR_IN_SECONDS, 'display' => __( 'Twice Daily' ) ),
   372 		'daily'      => array( 'interval' => DAY_IN_SECONDS,       'display' => __( 'Once Daily' ) ),
   430 		'daily'      => array( 'interval' => DAY_IN_SECONDS,       'display' => __( 'Once Daily' ) ),
   373 	);
   431 	);
   374 	/**
   432 	/**
   375 	 * Filter the non-default cron schedules.
   433 	 * Filters the non-default cron schedules.
   376 	 *
   434 	 *
   377 	 * @since 2.1.0
   435 	 * @since 2.1.0
   378 	 *
   436 	 *
   379 	 * @param array $new_schedules An array of non-default cron schedules. Default empty.
   437 	 * @param array $new_schedules An array of non-default cron schedules. Default empty.
   380 	 */
   438 	 */
   381 	return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
   439 	return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
   382 }
   440 }
   383 
   441 
   384 /**
   442 /**
   385  * Retrieve Cron schedule for hook with arguments.
   443  * Retrieve the recurrence schedule for an event.
   386  *
   444  *
   387  * @since 2.1.0
   445  * @see wp_get_schedules() for available schedules.
   388  *
   446  *
   389  * @param string $hook Action hook to execute when cron is run.
   447  * @since 2.1.0
   390  * @param array $args Optional. Arguments to pass to the hook's callback function.
   448  *
   391  * @return string|bool False, if no schedule. Schedule on success.
   449  * @param string $hook Action hook to identify the event.
       
   450  * @param array $args Optional. Arguments passed to the event's callback function.
       
   451  * @return string|false False, if no schedule. Schedule name on success.
   392  */
   452  */
   393 function wp_get_schedule($hook, $args = array()) {
   453 function wp_get_schedule($hook, $args = array()) {
   394 	$crons = _get_cron_array();
   454 	$crons = _get_cron_array();
   395 	$key = md5(serialize($args));
   455 	$key = md5(serialize($args));
   396 	if ( empty($crons) )
   456 	if ( empty($crons) )
   410  * Retrieve cron info array option.
   470  * Retrieve cron info array option.
   411  *
   471  *
   412  * @since 2.1.0
   472  * @since 2.1.0
   413  * @access private
   473  * @access private
   414  *
   474  *
   415  * @return array CRON info array.
   475  * @return false|array CRON info array.
   416  */
   476  */
   417 function _get_cron_array()  {
   477 function _get_cron_array()  {
   418 	$cron = get_option('cron');
   478 	$cron = get_option('cron');
   419 	if ( ! is_array($cron) )
   479 	if ( ! is_array($cron) )
   420 		return false;
   480 		return false;
   431  * Updates the CRON option with the new CRON array.
   491  * Updates the CRON option with the new CRON array.
   432  *
   492  *
   433  * @since 2.1.0
   493  * @since 2.1.0
   434  * @access private
   494  * @access private
   435  *
   495  *
   436  * @param array $cron Cron info array from {@link _get_cron_array()}.
   496  * @param array $cron Cron info array from _get_cron_array().
   437  */
   497  */
   438 function _set_cron_array($cron) {
   498 function _set_cron_array($cron) {
   439 	$cron['version'] = 2;
   499 	$cron['version'] = 2;
   440 	update_option( 'cron', $cron );
   500 	update_option( 'cron', $cron );
   441 }
   501 }
   446  * This function upgrades the Cron info array to version 2.
   506  * This function upgrades the Cron info array to version 2.
   447  *
   507  *
   448  * @since 2.1.0
   508  * @since 2.1.0
   449  * @access private
   509  * @access private
   450  *
   510  *
   451  * @param array $cron Cron info array from {@link _get_cron_array()}.
   511  * @param array $cron Cron info array from _get_cron_array().
   452  * @return array An upgraded Cron info array.
   512  * @return array An upgraded Cron info array.
   453  */
   513  */
   454 function _upgrade_cron_array($cron) {
   514 function _upgrade_cron_array($cron) {
   455 	if ( isset($cron['version']) && 2 == $cron['version'])
   515 	if ( isset($cron['version']) && 2 == $cron['version'])
   456 		return $cron;
   516 		return $cron;