2006-03-07 16:43:59 -05:00
|
|
|
<?php
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2016-08-26 05:22:30 -04:00
|
|
|
* WordPress Cron API
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2016-08-26 05:22:30 -04:00
|
|
|
* Schedules an event to run only once.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* Schedules a hook which will be triggered by WordPress at the specified time.
|
|
|
|
* The action will trigger when someone visits your WordPress site if the scheduled
|
|
|
|
* time has passed.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2016-07-25 08:23:30 -04:00
|
|
|
* Note that scheduling an event to occur within 10 minutes of an existing event
|
2016-08-26 05:22:30 -04:00
|
|
|
* with the same action hook will be ignored unless you pass unique `$args` values
|
2016-07-25 08:23:30 -04:00
|
|
|
* for each scheduled event.
|
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* Use wp_next_scheduled() to prevent duplicate events.
|
|
|
|
*
|
|
|
|
* Use wp_schedule_event() to schedule a recurring event.
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_schedule_event'} filter added to short-circuit the function.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
*
|
2019-07-25 18:45:57 -04:00
|
|
|
* @link https://developer.wordpress.org/reference/functions/wp_schedule_single_event/
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) for when to next run the event.
|
|
|
|
* @param string $hook Action hook to execute when the event is run.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param array $args Optional. Array containing arguments to pass to the
|
2021-02-03 06:08:04 -05:00
|
|
|
* hook's callback function. Each value in the array
|
|
|
|
* is passed to the callback as an individual parameter.
|
|
|
|
* The array keys are ignored. Default empty array.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if event successfully scheduled. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_schedule_single_event( $timestamp, $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-06 22:39:23 -04:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_timestamp',
|
|
|
|
__( 'Event timestamp must be a valid Unix timestamp.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:39:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => false,
|
|
|
|
'args' => $args,
|
|
|
|
);
|
2017-11-22 10:16:47 -05:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
|
|
|
* Filter to preflight or hijack scheduling an event.
|
|
|
|
*
|
|
|
|
* Returning a non-null value will short-circuit adding the event to the
|
|
|
|
* cron array, causing the function to return the filtered value instead.
|
|
|
|
*
|
|
|
|
* Both single events and recurring events are passed through this filter;
|
|
|
|
* single events have `$event->schedule` as false, whereas recurring events
|
2018-12-29 23:51:51 -05:00
|
|
|
* have this set to a recurrence from wp_get_schedules(). Recurring
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* events also have the integer recurrence interval set as `$event->interval`.
|
|
|
|
*
|
|
|
|
* For plugins replacing wp-cron, it is recommended you check for an
|
2018-12-29 23:51:51 -05:00
|
|
|
* identical event within ten minutes and apply the {@see 'schedule_event'}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* filter to check if another plugin has disallowed the event before scheduling.
|
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* Return true if the event was scheduled, false or a WP_Error if not.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue adding the event.
|
|
|
|
* @param stdClass $event {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* An object containing an event's data.
|
|
|
|
*
|
|
|
|
* @type string $hook Action hook to execute when the event is run.
|
|
|
|
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
|
|
|
|
* @type string|false $schedule How often the event should subsequently recur.
|
|
|
|
* @type array $args Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
|
|
|
|
* }
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_schedule_event', null, $event, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_schedule_event_false',
|
|
|
|
__( 'A plugin prevented the event from being scheduled.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2019-03-16 02:42:50 -04:00
|
|
|
/*
|
|
|
|
* Check for a duplicated event.
|
|
|
|
*
|
|
|
|
* Don't schedule an event if there's already an identical event
|
|
|
|
* within 10 minutes.
|
|
|
|
*
|
|
|
|
* When scheduling events within ten minutes of the current time,
|
|
|
|
* all past identical events are considered duplicates.
|
|
|
|
*
|
|
|
|
* When scheduling an event with a past timestamp (ie, before the
|
|
|
|
* current time) all events scheduled within the next ten minutes
|
|
|
|
* are considered duplicates.
|
|
|
|
*/
|
2021-10-18 08:51:58 -04:00
|
|
|
$crons = _get_cron_array();
|
|
|
|
if ( ! is_array( $crons ) ) {
|
|
|
|
$crons = array();
|
|
|
|
}
|
|
|
|
|
2019-03-16 02:42:50 -04:00
|
|
|
$key = md5( serialize( $event->args ) );
|
|
|
|
$duplicate = false;
|
|
|
|
|
|
|
|
if ( $event->timestamp < time() + 10 * MINUTE_IN_SECONDS ) {
|
|
|
|
$min_timestamp = 0;
|
|
|
|
} else {
|
|
|
|
$min_timestamp = $event->timestamp - 10 * MINUTE_IN_SECONDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $event->timestamp < time() ) {
|
|
|
|
$max_timestamp = time() + 10 * MINUTE_IN_SECONDS;
|
|
|
|
} else {
|
|
|
|
$max_timestamp = $event->timestamp + 10 * MINUTE_IN_SECONDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $crons as $event_timestamp => $cron ) {
|
|
|
|
if ( $event_timestamp < $min_timestamp ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( $event_timestamp > $max_timestamp ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( isset( $cron[ $event->hook ][ $key ] ) ) {
|
|
|
|
$duplicate = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $duplicate ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'duplicate_event',
|
|
|
|
__( 'A duplicate event already exists.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-19 00:01:11 -05:00
|
|
|
/**
|
2019-01-23 18:23:52 -05:00
|
|
|
* Modify an event before it is scheduled.
|
2013-11-19 00:01:11 -05:00
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
2020-05-03 15:38:08 -04:00
|
|
|
* @param stdClass|false $event {
|
|
|
|
* An object containing an event's data, or boolean false to prevent the event from being scheduled.
|
2016-08-26 05:22:30 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @type string $hook Action hook to execute when the event is run.
|
|
|
|
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
|
|
|
|
* @type string|false $schedule How often the event should subsequently recur.
|
|
|
|
* @type array $args Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
|
2016-08-26 05:22:30 -04:00
|
|
|
* }
|
2013-11-19 00:01:11 -05:00
|
|
|
*/
|
|
|
|
$event = apply_filters( 'schedule_event', $event );
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// A plugin disallowed this event.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $event ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'schedule_event_false',
|
|
|
|
__( 'A plugin disallowed this event.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-10-18 16:50:35 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
|
|
|
|
'schedule' => $event->schedule,
|
|
|
|
'args' => $event->args,
|
|
|
|
);
|
|
|
|
uksort( $crons, 'strnatcasecmp' );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
return _set_cron_array( $crons, $wp_error );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2017-11-22 10:16:47 -05:00
|
|
|
* Schedules a recurring event.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* Schedules a hook which will be triggered by WordPress at the specified interval.
|
|
|
|
* The action will trigger when someone visits your WordPress site if the scheduled
|
|
|
|
* time has passed.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* Valid values for the recurrence are 'hourly', 'daily', and 'twicedaily'. These can
|
2016-05-23 14:59:27 -04:00
|
|
|
* be extended using the {@see 'cron_schedules'} filter in wp_get_schedules().
|
2009-04-08 16:16:59 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* Note that scheduling an event to occur within 10 minutes of an existing event
|
|
|
|
* with the same action hook will be ignored unless you pass unique `$args` values
|
|
|
|
* for each scheduled event.
|
|
|
|
*
|
|
|
|
* Use wp_next_scheduled() to prevent duplicate events.
|
|
|
|
*
|
|
|
|
* Use wp_schedule_single_event() to schedule a non-recurring event.
|
2010-12-02 11:27:16 -05:00
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_schedule_event'} filter added to short-circuit the function.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
*
|
2019-07-25 18:45:57 -04:00
|
|
|
* @link https://developer.wordpress.org/reference/functions/wp_schedule_event/
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) for when to next run the event.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param string $recurrence How often the event should subsequently recur.
|
|
|
|
* See wp_get_schedules() for accepted values.
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param string $hook Action hook to execute when the event is run.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param array $args Optional. Array containing arguments to pass to the
|
2021-02-03 06:08:04 -05:00
|
|
|
* hook's callback function. Each value in the array
|
|
|
|
* is passed to the callback as an individual parameter.
|
|
|
|
* The array keys are ignored. Default empty array.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if event successfully scheduled. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-06 22:39:23 -04:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_timestamp',
|
|
|
|
__( 'Event timestamp must be a valid Unix timestamp.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:39:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:43:59 -05:00
|
|
|
$schedules = wp_get_schedules();
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $schedules[ $recurrence ] ) ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_schedule',
|
|
|
|
__( 'Event schedule does not exist.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:43:59 -05:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => $recurrence,
|
|
|
|
'args' => $args,
|
|
|
|
'interval' => $schedules[ $recurrence ]['interval'],
|
|
|
|
);
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
|
|
|
/** This filter is documented in wp-includes/cron.php */
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_schedule_event', null, $event, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_schedule_event_false',
|
|
|
|
__( 'A plugin prevented the event from being scheduled.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2013-11-19 00:01:11 -05:00
|
|
|
/** This filter is documented in wp-includes/cron.php */
|
|
|
|
$event = apply_filters( 'schedule_event', $event );
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// A plugin disallowed this event.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $event ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'schedule_event_false',
|
|
|
|
__( 'A plugin disallowed this event.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-10-18 16:50:35 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$key = md5( serialize( $event->args ) );
|
2010-10-18 16:50:35 -04:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
$crons = _get_cron_array();
|
Code Modernization: Check the return type of `_get_cron_array()` in `wp_schedule_event()`.
This fixes a "Deprecated: Automatic conversion of false to array is deprecated" warning on PHP 8.1.
In `wp_schedule_event()`, the cron info array is retrieved via a call to `_get_cron_array()`, but as the documentation (correctly) states, the return type of that function is `array|false`, where `false` is returned for a virgin site, with no cron jobs scheduled yet.
However, no type check is done on the return value, and the `wp_schedule_event()` function just blindly continues by assigning a value to a subkey of the `$crons` "array".
Fixed by adding validation for the returned value from `_get_cron_array()` and initializing an empty array if `false` was returned.
Reference: [https://developer.wordpress.org/reference/functions/_get_cron_array/ WordPress Developer Resources: _get_cron_array()]
Props jrf, hellofromTonya, lucatume, pbearne, iluy, pedromendonca, SergeyBiryukov.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51619
git-svn-id: http://core.svn.wordpress.org/trunk@51225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-08-16 11:23:57 -04:00
|
|
|
if ( ! is_array( $crons ) ) {
|
|
|
|
$crons = array();
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
|
|
|
|
'schedule' => $event->schedule,
|
|
|
|
'args' => $event->args,
|
|
|
|
'interval' => $event->interval,
|
|
|
|
);
|
|
|
|
uksort( $crons, 'strnatcasecmp' );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
return _set_cron_array( $crons, $wp_error );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2017-11-22 10:16:47 -05:00
|
|
|
* Reschedules a recurring event.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2018-09-03 00:04:25 -04:00
|
|
|
* Mainly for internal use, this takes the time stamp of a previously run
|
|
|
|
* recurring event and reschedules it for its next run.
|
|
|
|
*
|
2018-12-29 23:51:51 -05:00
|
|
|
* To change upcoming scheduled events, use wp_schedule_event() to
|
2018-09-03 00:04:25 -04:00
|
|
|
* change the recurrence frequency.
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_reschedule_event'} filter added to short-circuit the function.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2018-09-03 00:04:25 -04:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) for when the event was scheduled.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param string $recurrence How often the event should subsequently recur.
|
|
|
|
* See wp_get_schedules() for accepted values.
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param string $hook Action hook to execute when the event is run.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param array $args Optional. Array containing arguments to pass to the
|
2021-02-03 06:08:04 -05:00
|
|
|
* hook's callback function. Each value in the array
|
|
|
|
* is passed to the callback as an individual parameter.
|
|
|
|
* The array keys are ignored. Default empty array.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if event successfully rescheduled. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-06 22:39:23 -04:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_timestamp',
|
|
|
|
__( 'Event timestamp must be a valid Unix timestamp.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:39:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:43:59 -05:00
|
|
|
$schedules = wp_get_schedules();
|
2017-11-30 18:11:00 -05:00
|
|
|
$interval = 0;
|
2006-04-06 01:25:50 -04:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
// First we try to get the interval from the schedule.
|
2014-08-01 16:57:16 -04:00
|
|
|
if ( isset( $schedules[ $recurrence ] ) ) {
|
|
|
|
$interval = $schedules[ $recurrence ]['interval'];
|
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
|
|
|
// Now we try to get it from the saved interval in case the schedule disappears.
|
|
|
|
if ( 0 === $interval ) {
|
|
|
|
$scheduled_event = wp_get_scheduled_event( $hook, $args, $timestamp );
|
|
|
|
if ( $scheduled_event && isset( $scheduled_event->interval ) ) {
|
|
|
|
$interval = $scheduled_event->interval;
|
|
|
|
}
|
2014-08-01 16:57:16 -04:00
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => $recurrence,
|
|
|
|
'args' => $args,
|
|
|
|
'interval' => $interval,
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter to preflight or hijack rescheduling of events.
|
|
|
|
*
|
|
|
|
* Returning a non-null value will short-circuit the normal rescheduling
|
|
|
|
* process, causing the function to return the filtered value instead.
|
|
|
|
*
|
|
|
|
* For plugins replacing wp-cron, return true if the event was successfully
|
|
|
|
* rescheduled, false if not.
|
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue adding the event.
|
|
|
|
* @param stdClass $event {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* An object containing an event's data.
|
|
|
|
*
|
|
|
|
* @type string $hook Action hook to execute when the event is run.
|
|
|
|
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
|
|
|
|
* @type string|false $schedule How often the event should subsequently recur.
|
|
|
|
* @type array $args Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
|
|
|
|
* }
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-20 07:11:03 -05:00
|
|
|
$pre = apply_filters( 'pre_reschedule_event', null, $event, $wp_error );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_reschedule_event_false',
|
|
|
|
__( 'A plugin prevented the event from being rescheduled.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Now we assume something is wrong and fail to schedule.
|
2014-08-01 16:57:16 -04:00
|
|
|
if ( 0 == $interval ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_schedule',
|
|
|
|
__( 'Event schedule does not exist.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:43:59 -05:00
|
|
|
return false;
|
2014-08-01 16:57:16 -04:00
|
|
|
}
|
2006-03-07 16:43:59 -05:00
|
|
|
|
2009-04-16 20:23:48 -04:00
|
|
|
$now = time();
|
|
|
|
|
2014-08-01 16:57:16 -04:00
|
|
|
if ( $timestamp >= $now ) {
|
2010-06-29 20:05:18 -04:00
|
|
|
$timestamp = $now + $interval;
|
2014-08-01 16:57:16 -04:00
|
|
|
} else {
|
|
|
|
$timestamp = $now + ( $interval - ( ( $now - $timestamp ) % $interval ) );
|
|
|
|
}
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2021-02-02 08:49:03 -05:00
|
|
|
return wp_schedule_event( $timestamp, $recurrence, $hook, $args, $wp_error );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2016-08-26 05:22:30 -04:00
|
|
|
* Unschedule a previously scheduled event.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2016-08-26 05:22:30 -04:00
|
|
|
* The $timestamp and $hook parameters are required so that the event can be
|
2008-09-04 15:12:40 -04:00
|
|
|
* identified.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_unschedule_event'} filter added to short-circuit the function.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) of the event.
|
|
|
|
* @param string $hook Action hook of the event.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify the
|
|
|
|
* event, so they should be the same as those used when originally scheduling the event.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if event successfully unscheduled. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_unschedule_event( $timestamp, $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-06 22:39:23 -04:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_timestamp',
|
|
|
|
__( 'Event timestamp must be a valid Unix timestamp.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:39:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
|
|
|
* Filter to preflight or hijack unscheduling of events.
|
|
|
|
*
|
|
|
|
* Returning a non-null value will short-circuit the normal unscheduling
|
|
|
|
* process, causing the function to return the filtered value instead.
|
|
|
|
*
|
|
|
|
* For plugins replacing wp-cron, return true if the event was successfully
|
|
|
|
* unscheduled, false if not.
|
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue unscheduling the event.
|
|
|
|
* @param int $timestamp Timestamp for when to run the event.
|
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param array $args Arguments to pass to the hook's callback function.
|
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_unschedule_event', null, $timestamp, $hook, $args, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_unschedule_event_false',
|
|
|
|
__( 'A plugin prevented the event from being unscheduled.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2006-09-13 19:54:15 -04:00
|
|
|
$crons = _get_cron_array();
|
2017-11-30 18:11:00 -05:00
|
|
|
$key = md5( serialize( $args ) );
|
|
|
|
unset( $crons[ $timestamp ][ $hook ][ $key ] );
|
|
|
|
if ( empty( $crons[ $timestamp ][ $hook ] ) ) {
|
|
|
|
unset( $crons[ $timestamp ][ $hook ] );
|
|
|
|
}
|
|
|
|
if ( empty( $crons[ $timestamp ] ) ) {
|
|
|
|
unset( $crons[ $timestamp ] );
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
return _set_cron_array( $crons, $wp_error );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2017-06-30 00:54:41 -04:00
|
|
|
* Unschedules all events attached to the hook with the specified arguments.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* Warning: This function may return Boolean FALSE, but may also return a non-Boolean
|
|
|
|
* value which evaluates to FALSE. For information about casting to booleans see the
|
2020-01-19 22:14:06 -05:00
|
|
|
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to indicate success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_clear_scheduled_hook'} filter added to short-circuit the function.
|
2021-02-03 05:58:07 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2021-02-03 05:58:07 -05:00
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify the
|
|
|
|
* event, so they should be the same as those used when originally scheduling the event.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
2021-02-03 05:58:07 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @return int|false|WP_Error On success an integer indicating number of events unscheduled (0 indicates no
|
|
|
|
* events were registered with the hook and arguments combination), false or WP_Error
|
|
|
|
* if unscheduling one or more events fail.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_clear_scheduled_hook( $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Backward compatibility.
|
|
|
|
// Previously, this function took the arguments as discrete vars rather than an array like the rest of the API.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! is_array( $args ) ) {
|
|
|
|
_deprecated_argument( __FUNCTION__, '3.0.0', __( 'This argument has changed to an array to match the behavior of the other cron functions.' ) );
|
2021-02-02 13:04:03 -05:00
|
|
|
$args = array_slice( func_get_args(), 1 ); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
|
2021-02-02 08:49:03 -05:00
|
|
|
$wp_error = false;
|
2009-12-24 06:12:04 -05:00
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
|
|
|
* Filter to preflight or hijack clearing a scheduled hook.
|
|
|
|
*
|
|
|
|
* Returning a non-null value will short-circuit the normal unscheduling
|
|
|
|
* process, causing the function to return the filtered value instead.
|
|
|
|
*
|
|
|
|
* For plugins replacing wp-cron, return the number of events successfully
|
|
|
|
* unscheduled (zero if no events were registered with the hook) or false
|
|
|
|
* if unscheduling one or more events fails.
|
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|int|false|WP_Error $pre Value to return instead. Default null to continue unscheduling the event.
|
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param array $args Arguments to pass to the hook's callback function.
|
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_clear_scheduled_hook', null, $hook, $args, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_clear_scheduled_hook_false',
|
|
|
|
__( 'A plugin prevented the hook from being cleared.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* This logic duplicates wp_next_scheduled().
|
|
|
|
* It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing,
|
|
|
|
* and, wp_next_scheduled() returns the same schedule in an infinite loop.
|
|
|
|
*/
|
2013-12-07 04:13:11 -05:00
|
|
|
$crons = _get_cron_array();
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $crons ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-12-07 04:13:11 -05:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$results = array();
|
|
|
|
$key = md5( serialize( $args ) );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
2013-12-07 04:13:11 -05:00
|
|
|
foreach ( $crons as $timestamp => $cron ) {
|
|
|
|
if ( isset( $cron[ $hook ][ $key ] ) ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
$results[] = wp_unschedule_event( $timestamp, $hook, $args, true );
|
2013-12-07 04:13:11 -05:00
|
|
|
}
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
$errors = array_filter( $results, 'is_wp_error' );
|
|
|
|
$error = new WP_Error();
|
|
|
|
|
|
|
|
if ( $errors ) {
|
|
|
|
if ( $wp_error ) {
|
|
|
|
array_walk( $errors, array( $error, 'merge_from' ) );
|
|
|
|
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return count( $results );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2017-06-29 20:22:44 -04:00
|
|
|
/**
|
2017-06-30 00:54:41 -04:00
|
|
|
* Unschedules all events attached to the hook.
|
2017-06-29 20:22:44 -04:00
|
|
|
*
|
|
|
|
* Can be useful for plugins when deactivating to clean up the cron queue.
|
|
|
|
*
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* Warning: This function may return Boolean FALSE, but may also return a non-Boolean
|
|
|
|
* value which evaluates to FALSE. For information about casting to booleans see the
|
2020-01-19 22:14:06 -05:00
|
|
|
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2017-06-29 20:22:44 -04:00
|
|
|
* @since 4.9.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value added to indicate success or failure.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
2017-06-29 20:22:44 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return int|false|WP_Error On success an integer indicating number of events unscheduled (0 indicates no
|
|
|
|
* events were registered on the hook), false or WP_Error if unscheduling fails.
|
2017-06-29 20:22:44 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_unschedule_hook( $hook, $wp_error = false ) {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
|
|
|
* Filter to preflight or hijack clearing all events attached to the hook.
|
|
|
|
*
|
|
|
|
* Returning a non-null value will short-circuit the normal unscheduling
|
|
|
|
* process, causing the function to return the filtered value instead.
|
|
|
|
*
|
|
|
|
* For plugins replacing wp-cron, return the number of events successfully
|
|
|
|
* unscheduled (zero if no events were registered with the hook) or false
|
|
|
|
* if unscheduling one or more events fails.
|
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|int|false|WP_Error $pre Value to return instead. Default null to continue unscheduling the hook.
|
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_unschedule_hook', null, $hook, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_unschedule_hook_false',
|
|
|
|
__( 'A plugin prevented the hook from being cleared.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:22:44 -04:00
|
|
|
$crons = _get_cron_array();
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
if ( empty( $crons ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-29 20:22:44 -04:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$results = array();
|
2017-11-30 18:11:00 -05:00
|
|
|
foreach ( $crons as $timestamp => $args ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
if ( ! empty( $crons[ $timestamp ][ $hook ] ) ) {
|
|
|
|
$results[] = count( $crons[ $timestamp ][ $hook ] );
|
|
|
|
}
|
2017-06-29 20:22:44 -04:00
|
|
|
unset( $crons[ $timestamp ][ $hook ] );
|
|
|
|
|
|
|
|
if ( empty( $crons[ $timestamp ] ) ) {
|
|
|
|
unset( $crons[ $timestamp ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
/*
|
|
|
|
* If the results are empty (zero events to unschedule), no attempt
|
|
|
|
* to update the cron array is required.
|
|
|
|
*/
|
|
|
|
if ( empty( $results ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
$set = _set_cron_array( $crons, $wp_error );
|
|
|
|
|
|
|
|
if ( true === $set ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return array_sum( $results );
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
return $set;
|
2017-06-29 20:22:44 -04:00
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
|
|
|
* Retrieve a scheduled event.
|
|
|
|
*
|
2019-01-23 18:08:51 -05:00
|
|
|
* Retrieve the full event object for a given event, if no timestamp is specified the next
|
|
|
|
* scheduled event is returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
|
|
|
* @param string $hook Action hook of the event.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify the
|
|
|
|
* event, so they should be the same as those used when originally scheduling the event.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
|
|
|
* @param int|null $timestamp Optional. Unix timestamp (UTC) of the event. If not specified, the next scheduled event
|
|
|
|
* is returned. Default null.
|
2020-01-11 13:32:05 -05:00
|
|
|
* @return object|false The event object. False if the event does not exist.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
|
|
|
function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) {
|
|
|
|
/**
|
|
|
|
* Filter to preflight or hijack retrieving a scheduled event.
|
|
|
|
*
|
|
|
|
* Returning a non-null value will short-circuit the normal process,
|
|
|
|
* returning the filtered value instead.
|
|
|
|
*
|
|
|
|
* Return false if the event does not exist, otherwise an event object
|
|
|
|
* should be returned.
|
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2019-09-21 13:41:57 -04:00
|
|
|
* @param null|false|object $pre Value to return instead. Default null to continue retrieving the event.
|
|
|
|
* @param string $hook Action hook of the event.
|
|
|
|
* @param array $args Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify
|
|
|
|
* the event.
|
2019-01-23 18:08:51 -05:00
|
|
|
* @param int|null $timestamp Unix timestamp (UTC) of the event. Null to retrieve next scheduled event.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_get_scheduled_event', null, $hook, $args, $timestamp );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
if ( null !== $timestamp && ! is_numeric( $timestamp ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
$crons = _get_cron_array();
|
|
|
|
if ( empty( $crons ) ) {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
$key = md5( serialize( $args ) );
|
|
|
|
|
|
|
|
if ( ! $timestamp ) {
|
|
|
|
// Get next event.
|
|
|
|
$next = false;
|
|
|
|
foreach ( $crons as $timestamp => $cron ) {
|
|
|
|
if ( isset( $cron[ $hook ][ $key ] ) ) {
|
|
|
|
$next = $timestamp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( ! $next ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$timestamp = $next;
|
|
|
|
} elseif ( ! isset( $crons[ $timestamp ][ $hook ][ $key ] ) ) {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => $crons[ $timestamp ][ $hook ][ $key ]['schedule'],
|
|
|
|
'args' => $args,
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( isset( $crons[ $timestamp ][ $hook ][ $key ]['interval'] ) ) {
|
|
|
|
$event->interval = $crons[ $timestamp ][ $hook ][ $key ]['interval'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2016-08-26 05:22:30 -04:00
|
|
|
* Retrieve the next timestamp for an event.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param string $hook Action hook of the event.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify the
|
|
|
|
* event, so they should be the same as those used when originally scheduling the event.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
2020-01-11 13:32:05 -05:00
|
|
|
* @return int|false The Unix timestamp of the next time the event will occur. False if the event doesn't exist.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2006-09-13 19:54:15 -04:00
|
|
|
function wp_next_scheduled( $hook, $args = array() ) {
|
2019-01-23 18:08:51 -05:00
|
|
|
$next_event = wp_get_scheduled_event( $hook, $args );
|
|
|
|
if ( ! $next_event ) {
|
|
|
|
return false;
|
2006-09-13 19:54:15 -04:00
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
return $next_event->timestamp;
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-08-01 01:00:07 -04:00
|
|
|
/**
|
2015-12-19 03:20:27 -05:00
|
|
|
* Sends a request to run cron through HTTP request that doesn't halt page loading.
|
2008-08-01 01:00:07 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return values added.
|
2015-12-19 03:20:27 -05:00
|
|
|
*
|
2016-08-26 05:22:30 -04:00
|
|
|
* @param int $gmt_time Optional. Unix timestamp (UTC). Default 0 (current time is used).
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* @return bool True if spawned, false if no events spawned.
|
2008-08-01 01:00:07 -04:00
|
|
|
*/
|
2012-09-23 12:57:21 -04:00
|
|
|
function spawn_cron( $gmt_time = 0 ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $gmt_time ) {
|
2012-09-23 12:57:21 -04:00
|
|
|
$gmt_time = microtime( true );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2009-02-07 08:32:34 -05:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( defined( 'DOING_CRON' ) || isset( $_GET['doing_wp_cron'] ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2008-09-18 03:09:38 -04:00
|
|
|
|
2009-02-07 08:32:34 -05:00
|
|
|
/*
|
2016-08-26 05:22:30 -04:00
|
|
|
* Get the cron lock, which is a Unix timestamp of when the last cron was spawned
|
2015-05-25 02:25:25 -04:00
|
|
|
* and has not finished running.
|
|
|
|
*
|
|
|
|
* Multiple processes on multiple web servers can run this code concurrently,
|
|
|
|
* this lock attempts to make spawning as atomic as possible.
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
$lock = get_transient( 'doing_cron' );
|
2009-02-07 08:32:34 -05:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $lock > $gmt_time + 10 * MINUTE_IN_SECONDS ) {
|
2011-09-09 15:59:44 -04:00
|
|
|
$lock = 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2009-02-07 08:32:34 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Don't run if another process is currently running it or more than once every 60 sec.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $lock + WP_CRON_LOCK_TIMEOUT > $gmt_time ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2009-02-07 08:32:34 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Sanity check.
|
2019-01-08 16:49:49 -05:00
|
|
|
$crons = wp_get_ready_cron_jobs();
|
|
|
|
if ( empty( $crons ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-06-27 02:04:27 -04:00
|
|
|
$keys = array_keys( $crons );
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2014-09-11 10:02:15 -04:00
|
|
|
if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( 'GET' !== $_SERVER['REQUEST_METHOD'] || defined( 'DOING_AJAX' ) || defined( 'XMLRPC_REQUEST' ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2014-09-11 10:02:15 -04:00
|
|
|
}
|
2008-09-18 03:09:38 -04:00
|
|
|
|
2012-09-23 12:57:21 -04:00
|
|
|
$doing_wp_cron = sprintf( '%.22F', $gmt_time );
|
2011-09-09 15:59:44 -04:00
|
|
|
set_transient( 'doing_cron', $doing_wp_cron );
|
2009-02-07 08:32:34 -05:00
|
|
|
|
|
|
|
ob_start();
|
2013-03-03 11:30:38 -05:00
|
|
|
wp_redirect( add_query_arg( 'doing_wp_cron', $doing_wp_cron, wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
|
2009-02-07 08:32:34 -05:00
|
|
|
echo ' ';
|
2008-09-18 03:09:38 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Flush any buffers and send the headers.
|
2019-07-09 01:45:58 -04:00
|
|
|
wp_ob_end_flush_all();
|
2009-02-07 08:32:34 -05:00
|
|
|
flush();
|
|
|
|
|
2020-02-06 01:33:11 -05:00
|
|
|
include_once ABSPATH . 'wp-cron.php';
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return true;
|
2009-02-07 08:32:34 -05:00
|
|
|
}
|
2008-09-18 03:09:38 -04:00
|
|
|
|
2015-05-25 02:25:25 -04:00
|
|
|
// Set the cron lock with the current unix timestamp, when the cron is being spawned.
|
2012-09-23 12:57:21 -04:00
|
|
|
$doing_wp_cron = sprintf( '%.22F', $gmt_time );
|
2011-09-09 15:59:44 -04:00
|
|
|
set_transient( 'doing_cron', $doing_wp_cron );
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2013-11-19 00:01:11 -05:00
|
|
|
/**
|
2016-05-22 14:50:28 -04:00
|
|
|
* Filters the cron request arguments.
|
2013-11-19 00:01:11 -05:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
2016-01-14 12:30:28 -05:00
|
|
|
* @since 4.5.0 The `$doing_wp_cron` parameter was added.
|
2013-11-19 00:01:11 -05:00
|
|
|
*
|
|
|
|
* @param array $cron_request_array {
|
|
|
|
* An array of cron request URL arguments.
|
|
|
|
*
|
|
|
|
* @type string $url The cron request URL.
|
|
|
|
* @type int $key The 22 digit GMT microtime.
|
|
|
|
* @type array $args {
|
|
|
|
* An array of cron request arguments.
|
|
|
|
*
|
|
|
|
* @type int $timeout The request timeout in seconds. Default .01 seconds.
|
|
|
|
* @type bool $blocking Whether to set blocking for the request. Default false.
|
2014-06-19 18:53:19 -04:00
|
|
|
* @type bool $sslverify Whether SSL should be verified for the request. Default false.
|
2013-11-19 00:01:11 -05:00
|
|
|
* }
|
|
|
|
* }
|
2016-01-08 18:54:26 -05:00
|
|
|
* @param string $doing_wp_cron The unix timestamp of the cron lock.
|
2013-11-19 00:01:11 -05:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
$cron_request = apply_filters(
|
2018-08-16 21:51:36 -04:00
|
|
|
'cron_request',
|
|
|
|
array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'url' => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ),
|
|
|
|
'key' => $doing_wp_cron,
|
|
|
|
'args' => array(
|
|
|
|
'timeout' => 0.01,
|
|
|
|
'blocking' => false,
|
|
|
|
/** This filter is documented in wp-includes/class-wp-http-streams.php */
|
|
|
|
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
|
|
|
|
),
|
2018-08-16 21:51:36 -04:00
|
|
|
),
|
|
|
|
$doing_wp_cron
|
2017-11-30 18:11:00 -05:00
|
|
|
);
|
2012-07-20 11:15:22 -04:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$result = wp_remote_post( $cron_request['url'], $cron_request['args'] );
|
|
|
|
return ! is_wp_error( $result );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
Cron API: Run alternative wp-cron later, do not run on archived blogs.
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 22:10:08 -05:00
|
|
|
* Register _wp_cron() to run on the {@see 'wp_loaded'} action.
|
|
|
|
*
|
|
|
|
* If the {@see 'wp_loaded'} action has already fired, this function calls
|
|
|
|
* _wp_cron() directly.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* Warning: This function may return Boolean FALSE, but may also return a non-Boolean
|
|
|
|
* value which evaluates to FALSE. For information about casting to booleans see the
|
2020-01-19 22:14:06 -05:00
|
|
|
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value added to indicate success or failure.
|
Cron API: Run alternative wp-cron later, do not run on archived blogs.
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 22:10:08 -05:00
|
|
|
* @since 5.7.0 Functionality moved to _wp_cron() to which this becomes a wrapper.
|
|
|
|
*
|
|
|
|
* @return bool|int|void On success an integer indicating number of events spawned (0 indicates no
|
|
|
|
* events needed to be spawned), false if spawning fails for one or more events or
|
|
|
|
* void if the function registered _wp_cron() to run on the action.
|
|
|
|
*/
|
|
|
|
function wp_cron() {
|
|
|
|
if ( did_action( 'wp_loaded' ) ) {
|
|
|
|
return _wp_cron();
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'wp_loaded', '_wp_cron', 20 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run scheduled callbacks or spawn cron for all scheduled events.
|
|
|
|
*
|
|
|
|
* Warning: This function may return Boolean FALSE, but may also return a non-Boolean
|
|
|
|
* value which evaluates to FALSE. For information about casting to booleans see the
|
|
|
|
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
|
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
|
|
|
* @since 5.7.0
|
|
|
|
* @access private
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
*
|
2021-01-04 12:18:04 -05:00
|
|
|
* @return int|false On success an integer indicating number of events spawned (0 indicates no
|
2021-01-03 17:04:04 -05:00
|
|
|
* events needed to be spawned), false if spawning fails for one or more events.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
Cron API: Run alternative wp-cron later, do not run on archived blogs.
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 22:10:08 -05:00
|
|
|
function _wp_cron() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Prevent infinite loops caused by lack of wp-cron.php.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( strpos( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) !== false || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2007-01-30 08:06:56 -05:00
|
|
|
|
2019-01-08 16:49:49 -05:00
|
|
|
$crons = wp_get_ready_cron_jobs();
|
|
|
|
if ( empty( $crons ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-06-10 16:43:49 -04:00
|
|
|
|
2012-09-23 12:57:21 -04:00
|
|
|
$gmt_time = microtime( true );
|
2017-11-30 18:11:00 -05:00
|
|
|
$keys = array_keys( $crons );
|
|
|
|
if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-03-07 16:43:59 -05:00
|
|
|
|
|
|
|
$schedules = wp_get_schedules();
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$results = array();
|
2006-04-06 01:25:50 -04:00
|
|
|
foreach ( $crons as $timestamp => $cronhooks ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $timestamp > $gmt_time ) {
|
|
|
|
break;
|
|
|
|
}
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $cronhooks as $hook => $args ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( isset( $schedules[ $hook ]['callback'] ) && ! call_user_func( $schedules[ $hook ]['callback'] ) ) {
|
2006-03-07 16:43:59 -05:00
|
|
|
continue;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$results[] = spawn_cron( $gmt_time );
|
2006-03-07 16:43:59 -05:00
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
}
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
|
|
|
|
if ( in_array( false, $results, true ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return count( $results );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2016-08-26 05:22:30 -04:00
|
|
|
* Retrieve supported event recurrence schedules.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2020-01-12 06:20:04 -05:00
|
|
|
* The default supported recurrences are 'hourly', 'twicedaily', 'daily', and 'weekly'.
|
|
|
|
* A plugin may add more by hooking into the {@see 'cron_schedules'} filter.
|
|
|
|
* The filter accepts an array of arrays. The outer array has a key that is the name
|
|
|
|
* of the schedule, for example 'monthly'. The value is an array with two keys,
|
|
|
|
* one is 'interval' and the other is 'display'.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2020-01-12 06:20:04 -05:00
|
|
|
* The 'interval' is a number in seconds of when the cron job should run.
|
|
|
|
* So for 'hourly' the time is `HOUR_IN_SECONDS` (60 * 60 or 3600). For 'monthly',
|
|
|
|
* the value would be `MONTH_IN_SECONDS` (30 * 24 * 60 * 60 or 2592000).
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2020-01-12 06:20:04 -05:00
|
|
|
* The 'display' is the description. For the 'monthly' key, the 'display'
|
|
|
|
* would be `__( 'Once Monthly' )`.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2020-01-12 06:20:04 -05:00
|
|
|
* For your plugin, you will be passed an array. You can easily add your
|
2008-09-04 15:12:40 -04:00
|
|
|
* schedule by doing the following.
|
2014-11-23 23:58:22 -05:00
|
|
|
*
|
|
|
|
* // Filter parameter variable name is 'array'.
|
2020-01-12 06:20:04 -05:00
|
|
|
* $array['monthly'] = array(
|
|
|
|
* 'interval' => MONTH_IN_SECONDS,
|
|
|
|
* 'display' => __( 'Once Monthly' )
|
2014-11-23 23:58:22 -05:00
|
|
|
* );
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2020-01-12 06:20:04 -05:00
|
|
|
* @since 5.4.0 The 'weekly' schedule was added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2021-10-29 19:13:05 -04:00
|
|
|
* @return array[]
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2006-03-07 16:43:59 -05:00
|
|
|
function wp_get_schedules() {
|
|
|
|
$schedules = array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'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' ),
|
|
|
|
),
|
2020-01-12 06:20:04 -05:00
|
|
|
'weekly' => array(
|
2020-01-13 12:05:07 -05:00
|
|
|
'interval' => WEEK_IN_SECONDS,
|
2020-01-12 06:20:04 -05:00
|
|
|
'display' => __( 'Once Weekly' ),
|
|
|
|
),
|
2006-03-07 16:43:59 -05:00
|
|
|
);
|
2020-01-12 06:20:04 -05:00
|
|
|
|
2013-11-19 00:01:11 -05:00
|
|
|
/**
|
2016-05-22 14:50:28 -04:00
|
|
|
* Filters the non-default cron schedules.
|
2013-11-19 00:01:11 -05:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
2021-10-29 19:13:05 -04:00
|
|
|
* @param array[] $new_schedules An array of non-default cron schedule arrays. Default empty.
|
2013-11-19 00:01:11 -05:00
|
|
|
*/
|
2006-04-06 01:25:50 -04:00
|
|
|
return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2016-08-26 05:22:30 -04:00
|
|
|
* Retrieve the recurrence schedule for an event.
|
|
|
|
*
|
|
|
|
* @see wp_get_schedules() for available schedules.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0 {@see 'get_schedule'} filter added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2016-08-26 05:22:30 -04:00
|
|
|
* @param string $hook Action hook to identify the event.
|
2020-07-23 17:11:05 -04:00
|
|
|
* @param array $args Optional. Arguments passed to the event's callback function.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
2021-01-15 15:08:07 -05:00
|
|
|
* @return string|false Schedule name on success, false if no schedule.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
function wp_get_schedule( $hook, $args = array() ) {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
$schedule = false;
|
|
|
|
$event = wp_get_scheduled_event( $hook, $args );
|
|
|
|
|
|
|
|
if ( $event ) {
|
|
|
|
$schedule = $event->schedule;
|
2006-09-25 21:14:49 -04:00
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
|
|
|
/**
|
2020-08-10 20:34:08 -04:00
|
|
|
* Filters the schedule for a hook.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-01-03 17:04:04 -05:00
|
|
|
* @param string|false $schedule Schedule for the hook. False if not found.
|
|
|
|
* @param string $hook Action hook to execute when cron is run.
|
2021-02-03 06:08:04 -05:00
|
|
|
* @param array $args Arguments to pass to the hook's callback function.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
|
|
|
return apply_filters( 'get_schedule', $schedule, $hook, $args );
|
2006-09-25 21:14:49 -04:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:49:49 -05:00
|
|
|
/**
|
|
|
|
* Retrieve cron jobs ready to be run.
|
|
|
|
*
|
|
|
|
* Returns the results of _get_cron_array() limited to events ready to be run,
|
|
|
|
* ie, with a timestamp in the past.
|
|
|
|
*
|
|
|
|
* @since 5.1.0
|
|
|
|
*
|
|
|
|
* @return array Cron jobs ready to be run.
|
|
|
|
*/
|
|
|
|
function wp_get_ready_cron_jobs() {
|
|
|
|
/**
|
|
|
|
* Filter to preflight or hijack retrieving ready cron jobs.
|
|
|
|
*
|
|
|
|
* Returning an array will short-circuit the normal retrieval of ready
|
|
|
|
* cron jobs, causing the function to return the filtered value instead.
|
|
|
|
*
|
|
|
|
* @since 5.1.0
|
|
|
|
*
|
|
|
|
* @param null|array $pre Array of ready cron tasks to return instead. Default null
|
|
|
|
* to continue using results from _get_cron_array().
|
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_get_ready_cron_jobs', null );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
|
|
|
$crons = _get_cron_array();
|
Code Modernization: Check the return type of `_get_cron_array()` in `wp_schedule_event()`.
This fixes a "Deprecated: Automatic conversion of false to array is deprecated" warning on PHP 8.1.
In `wp_schedule_event()`, the cron info array is retrieved via a call to `_get_cron_array()`, but as the documentation (correctly) states, the return type of that function is `array|false`, where `false` is returned for a virgin site, with no cron jobs scheduled yet.
However, no type check is done on the return value, and the `wp_schedule_event()` function just blindly continues by assigning a value to a subkey of the `$crons` "array".
Fixed by adding validation for the returned value from `_get_cron_array()` and initializing an empty array if `false` was returned.
Reference: [https://developer.wordpress.org/reference/functions/_get_cron_array/ WordPress Developer Resources: _get_cron_array()]
Props jrf, hellofromTonya, lucatume, pbearne, iluy, pedromendonca, SergeyBiryukov.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51619
git-svn-id: http://core.svn.wordpress.org/trunk@51225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-08-16 11:23:57 -04:00
|
|
|
if ( ! is_array( $crons ) ) {
|
2019-01-08 16:49:49 -05:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$gmt_time = microtime( true );
|
|
|
|
$keys = array_keys( $crons );
|
|
|
|
if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = array();
|
|
|
|
foreach ( $crons as $timestamp => $cronhooks ) {
|
|
|
|
if ( $timestamp > $gmt_time ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$results[ $timestamp ] = $cronhooks;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
2006-09-13 19:54:15 -04:00
|
|
|
//
|
2020-01-28 19:45:18 -05:00
|
|
|
// Private functions.
|
2006-09-13 19:54:15 -04:00
|
|
|
//
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
|
|
|
* Retrieve cron info array option.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @access private
|
|
|
|
*
|
2021-01-15 15:08:07 -05:00
|
|
|
* @return array|false Cron info array on success, false on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
function _get_cron_array() {
|
|
|
|
$cron = get_option( 'cron' );
|
|
|
|
if ( ! is_array( $cron ) ) {
|
2006-09-13 19:54:15 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-09-13 19:54:15 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $cron['version'] ) ) {
|
|
|
|
$cron = _upgrade_cron_array( $cron );
|
|
|
|
}
|
2006-09-13 19:54:15 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
unset( $cron['version'] );
|
2006-09-13 19:54:15 -04:00
|
|
|
|
|
|
|
return $cron;
|
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2021-02-02 08:49:03 -05:00
|
|
|
* Updates the cron option with the new cron array.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-29 23:51:51 -05:00
|
|
|
* @since 5.1.0 Return value modified to outcome of update_option().
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @access private
|
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param array $cron Cron info array from _get_cron_array().
|
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if cron array updated. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function _set_cron_array( $cron, $wp_error = false ) {
|
2021-08-30 11:20:56 -04:00
|
|
|
if ( ! is_array( $cron ) ) {
|
|
|
|
$cron = array();
|
|
|
|
}
|
|
|
|
|
2006-09-13 19:54:15 -04:00
|
|
|
$cron['version'] = 2;
|
2021-02-02 13:04:03 -05:00
|
|
|
$result = update_option( 'cron', $cron );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
if ( $wp_error && ! $result ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'could_not_set',
|
|
|
|
__( 'The cron event list could not be saved.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
2006-09-13 19:54:15 -04:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
|
|
|
* Upgrade a Cron info array.
|
|
|
|
*
|
|
|
|
* This function upgrades the Cron info array to version 2.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @access private
|
|
|
|
*
|
2016-05-22 13:39:28 -04:00
|
|
|
* @param array $cron Cron info array from _get_cron_array().
|
2008-09-04 15:12:40 -04:00
|
|
|
* @return array An upgraded Cron info array.
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
function _upgrade_cron_array( $cron ) {
|
|
|
|
if ( isset( $cron['version'] ) && 2 == $cron['version'] ) {
|
2006-09-13 19:54:15 -04:00
|
|
|
return $cron;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-09-13 19:54:15 -04:00
|
|
|
|
|
|
|
$new_cron = array();
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
foreach ( (array) $cron as $timestamp => $hooks ) {
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $hooks as $hook => $args ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$key = md5( serialize( $args['args'] ) );
|
|
|
|
$new_cron[ $timestamp ][ $hook ][ $key ] = $args;
|
2006-09-13 19:54:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$new_cron['version'] = 2;
|
|
|
|
update_option( 'cron', $new_cron );
|
|
|
|
return $new_cron;
|
2010-12-02 11:27:16 -05:00
|
|
|
}
|