2006-03-07 22:43:59 +01:00
|
|
|
<?php
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
2016-08-26 11:22:30 +02:00
|
|
|
* WordPress Cron API
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
2006-04-06 07:25:50 +02:00
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
2016-08-26 11:22:30 +02:00
|
|
|
* Schedules an event to run only once.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2017-11-22 16:16:47 +01: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 21:12:40 +02:00
|
|
|
*
|
2016-07-25 14:23:30 +02:00
|
|
|
* Note that scheduling an event to occur within 10 minutes of an existing event
|
2016-08-26 11:22:30 +02:00
|
|
|
* with the same action hook will be ignored unless you pass unique `$args` values
|
2016-07-25 14:23:30 +02:00
|
|
|
* for each scheduled event.
|
|
|
|
*
|
2017-11-22 16:16:47 +01:00
|
|
|
* Use wp_next_scheduled() to prevent duplicate events.
|
|
|
|
*
|
|
|
|
* Use wp_schedule_event() to schedule a recurring event.
|
|
|
|
*
|
2008-09-04 21:12:40 +02:00
|
|
|
* @since 2.1.0
|
2018-12-19 04:41:49 +01:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-30 05:51:51 +01:00
|
|
|
* {@see 'pre_schedule_event'} filter added to short-circuit the function.
|
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-05-01 04:05:23 +02:00
|
|
|
*
|
2019-07-26 00:45:57 +02:00
|
|
|
* @link https://developer.wordpress.org/reference/functions/wp_schedule_single_event/
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2017-11-22 16:16:47 +01: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.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
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-05-01 04:05:23 +02:00
|
|
|
* @return bool True if event successfully scheduled. False for failure.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2017-12-01 00:11:00 +01:00
|
|
|
function wp_schedule_single_event( $timestamp, $hook, $args = array() ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-07 04:39:23 +02:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => false,
|
|
|
|
'args' => $args,
|
|
|
|
);
|
2017-11-22 16:16:47 +01: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-27 04:23:25 +02: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-30 05:51:51 +01: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-27 04:23:25 +02: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-30 05:51:51 +01: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-27 04:23:25 +02:00
|
|
|
* filter to check if another plugin has disallowed the event before scheduling.
|
|
|
|
*
|
|
|
|
* Return true if the event was scheduled, false if not.
|
|
|
|
*
|
2018-12-30 06:06:48 +01: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-27 04:23:25 +02:00
|
|
|
*
|
|
|
|
* @param null|bool $pre Value to return instead. Default null to continue adding the event.
|
|
|
|
* @param stdClass $event {
|
|
|
|
* 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.
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_schedule_event', null, $event );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2019-03-16 07:42:50 +01: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.
|
|
|
|
*/
|
|
|
|
$crons = (array) _get_cron_array();
|
|
|
|
$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 ) {
|
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-27 04:23:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-19 06:01:11 +01:00
|
|
|
/**
|
2019-01-24 00:23:52 +01:00
|
|
|
* Modify an event before it is scheduled.
|
2013-11-19 06:01:11 +01:00
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
2016-08-26 11:22:30 +02:00
|
|
|
* @param stdClass $event {
|
|
|
|
* An object containing an event's data.
|
|
|
|
*
|
2017-11-22 16:16:47 +01: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 11:22:30 +02:00
|
|
|
* }
|
2013-11-19 06:01:11 +01:00
|
|
|
*/
|
|
|
|
$event = apply_filters( 'schedule_event', $event );
|
2010-10-18 22:50:35 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// A plugin disallowed this event.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $event ) {
|
2010-10-18 22:50:35 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-10-18 22:50:35 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
|
|
|
|
'schedule' => $event->schedule,
|
|
|
|
'args' => $event->args,
|
|
|
|
);
|
|
|
|
uksort( $crons, 'strnatcasecmp' );
|
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-05-01 04:05:23 +02:00
|
|
|
return _set_cron_array( $crons );
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
2006-04-06 07:25:50 +02:00
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
2017-11-22 16:16:47 +01:00
|
|
|
* Schedules a recurring event.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2017-11-22 16:16:47 +01: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 21:12:40 +02:00
|
|
|
*
|
2017-11-22 16:16:47 +01:00
|
|
|
* Valid values for the recurrence are 'hourly', 'daily', and 'twicedaily'. These can
|
2016-05-23 20:59:27 +02:00
|
|
|
* be extended using the {@see 'cron_schedules'} filter in wp_get_schedules().
|
2009-04-08 22:16:59 +02:00
|
|
|
*
|
2017-11-22 16:16:47 +01: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 17:27:16 +01:00
|
|
|
*
|
2008-09-04 21:12:40 +02:00
|
|
|
* @since 2.1.0
|
2018-12-19 04:41:49 +01:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-30 05:51:51 +01:00
|
|
|
* {@see 'pre_schedule_event'} filter added to short-circuit the function.
|
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-05-01 04:05:23 +02:00
|
|
|
*
|
2019-07-26 00:45:57 +02:00
|
|
|
* @link https://developer.wordpress.org/reference/functions/wp_schedule_event/
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2017-11-22 16:16:47 +01:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) for when to next run the event.
|
|
|
|
* @param string $recurrence How often the event should subsequently recur. See wp_get_schedules() for accepted values.
|
|
|
|
* @param string $hook Action hook to execute when the event is run.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
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-05-01 04:05:23 +02:00
|
|
|
* @return bool True if event successfully scheduled. False for failure.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2017-12-01 00:11:00 +01:00
|
|
|
function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-07 04:39:23 +02:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-03-07 22:43:59 +01:00
|
|
|
$schedules = wp_get_schedules();
|
2010-10-18 22:50:35 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! isset( $schedules[ $recurrence ] ) ) {
|
2006-03-07 22:43:59 +01:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-10-18 22:50:35 +02:00
|
|
|
|
2017-12-01 00:11:00 +01: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-27 04:23:25 +02:00
|
|
|
|
|
|
|
/** This filter is documented in wp-includes/cron.php */
|
|
|
|
$pre = apply_filters( 'pre_schedule_event', null, $event );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2013-11-19 06:01:11 +01:00
|
|
|
/** This filter is documented in wp-includes/cron.php */
|
|
|
|
$event = apply_filters( 'schedule_event', $event );
|
2010-10-18 22:50:35 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// A plugin disallowed this event.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $event ) {
|
2010-10-18 22:50:35 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-10-18 22:50:35 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$key = md5( serialize( $event->args ) );
|
2010-10-18 22:50:35 +02: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-27 04:23:25 +02:00
|
|
|
$crons = _get_cron_array();
|
2017-12-01 00:11:00 +01:00
|
|
|
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
|
|
|
|
'schedule' => $event->schedule,
|
|
|
|
'args' => $event->args,
|
|
|
|
'interval' => $event->interval,
|
|
|
|
);
|
|
|
|
uksort( $crons, 'strnatcasecmp' );
|
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-05-01 04:05:23 +02:00
|
|
|
return _set_cron_array( $crons );
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
2017-11-22 16:16:47 +01:00
|
|
|
* Reschedules a recurring event.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2018-09-03 06:04:25 +02: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-30 05:51:51 +01:00
|
|
|
* To change upcoming scheduled events, use wp_schedule_event() to
|
2018-09-03 06:04:25 +02:00
|
|
|
* change the recurrence frequency.
|
|
|
|
*
|
2008-09-04 21:12:40 +02:00
|
|
|
* @since 2.1.0
|
2018-12-19 04:41:49 +01:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-30 05:51:51 +01:00
|
|
|
* {@see 'pre_reschedule_event'} filter added to short-circuit the function.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2018-09-03 06:04:25 +02:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) for when the event was scheduled.
|
2017-11-22 16:16:47 +01:00
|
|
|
* @param string $recurrence How often the event should subsequently recur. See wp_get_schedules() for accepted values.
|
|
|
|
* @param string $hook Action hook to execute when the event is run.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
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-05-01 04:05:23 +02:00
|
|
|
* @return bool True if event successfully rescheduled. False for failure.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2014-08-01 22:57:16 +02:00
|
|
|
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-07 04:39:23 +02:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-03-07 22:43:59 +01:00
|
|
|
$schedules = wp_get_schedules();
|
2017-12-01 00:11:00 +01:00
|
|
|
$interval = 0;
|
2006-04-06 07:25:50 +02: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-27 04:23:25 +02:00
|
|
|
// First we try to get the interval from the schedule.
|
2014-08-01 22:57:16 +02: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-27 04:23:25 +02: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 22:57:16 +02: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-27 04:23:25 +02: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 06:06:48 +01: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-27 04:23:25 +02:00
|
|
|
*
|
|
|
|
* @param null|bool $pre Value to return instead. Default null to continue adding the event.
|
|
|
|
* @param stdClass $event {
|
|
|
|
* 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.
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_reschedule_event', null, $event );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Now we assume something is wrong and fail to schedule.
|
2014-08-01 22:57:16 +02:00
|
|
|
if ( 0 == $interval ) {
|
2006-03-07 22:43:59 +01:00
|
|
|
return false;
|
2014-08-01 22:57:16 +02:00
|
|
|
}
|
2006-03-07 22:43:59 +01:00
|
|
|
|
2009-04-17 02:23:48 +02:00
|
|
|
$now = time();
|
|
|
|
|
2014-08-01 22:57:16 +02:00
|
|
|
if ( $timestamp >= $now ) {
|
2010-06-30 02:05:18 +02:00
|
|
|
$timestamp = $now + $interval;
|
2014-08-01 22:57:16 +02:00
|
|
|
} else {
|
|
|
|
$timestamp = $now + ( $interval - ( ( $now - $timestamp ) % $interval ) );
|
|
|
|
}
|
2006-04-06 07:25:50 +02: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-05-01 04:05:23 +02:00
|
|
|
return wp_schedule_event( $timestamp, $recurrence, $hook, $args );
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
2016-08-26 11:22:30 +02:00
|
|
|
* Unschedule a previously scheduled event.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2016-08-26 11:22:30 +02:00
|
|
|
* The $timestamp and $hook parameters are required so that the event can be
|
2008-09-04 21:12:40 +02:00
|
|
|
* identified.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-19 04:41:49 +01:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-30 05:51:51 +01:00
|
|
|
* {@see 'pre_unschedule_event'} filter added to short-circuit the function.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2017-11-22 16:16:47 +01: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.
|
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-05-01 04:05:23 +02:00
|
|
|
* @return bool True if event successfully unscheduled. False for failure.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2006-09-14 01:54:15 +02:00
|
|
|
function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-07 04:39:23 +02:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
|
|
|
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-27 04:23:25 +02: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 06:06:48 +01: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-27 04:23:25 +02:00
|
|
|
*
|
|
|
|
* @param null|bool $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.
|
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_unschedule_event', null, $timestamp, $hook, $args );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2006-09-14 01:54:15 +02:00
|
|
|
$crons = _get_cron_array();
|
2017-12-01 00:11:00 +01: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 ] );
|
|
|
|
}
|
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-05-01 04:05:23 +02:00
|
|
|
return _set_cron_array( $crons );
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
2017-06-30 06:54:41 +02:00
|
|
|
* Unschedules all events attached to the hook with the specified arguments.
|
2008-09-04 21:12:40 +02: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-05-01 04:05:23 +02: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-20 04:14:06 +01: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-05-01 04:05:23 +02:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2008-09-04 21:12:40 +02:00
|
|
|
* @since 2.1.0
|
2018-12-19 04:41:49 +01:00
|
|
|
* @since 5.1.0 Return value modified to indicate success or failure,
|
2018-12-30 05:51:51 +01:00
|
|
|
* {@see 'pre_clear_scheduled_hook'} filter added to short-circuit the function.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2008-12-19 21:47:20 +01:00
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
2019-09-21 19:41:57 +02:00
|
|
|
* @param array $args Optional. Arguments that were to be passed to the hook's callback function.
|
2020-01-11 19:32:05 +01:00
|
|
|
* @return int|false On success an integer indicating number of events unscheduled (0 indicates no
|
2019-09-21 19:41:57 +02:00
|
|
|
* events were registered with the hook and arguments combination), false if
|
|
|
|
* unscheduling one or more events fail.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2009-12-19 12:47:16 +01:00
|
|
|
function wp_clear_scheduled_hook( $hook, $args = array() ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Backward compatibility.
|
|
|
|
// Previously, this function took the arguments as discrete vars rather than an array like the rest of the API.
|
2017-12-01 00:11:00 +01: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.' ) );
|
2009-12-19 12:47:16 +01:00
|
|
|
$args = array_slice( func_get_args(), 1 );
|
2009-12-24 12:12:04 +01:00
|
|
|
}
|
2007-02-27 16:24:54 +01: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-27 04:23:25 +02: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 06:06:48 +01: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-27 04:23:25 +02:00
|
|
|
*
|
2019-09-21 19:41:57 +02:00
|
|
|
* @param null|int|false $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.
|
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-27 04:23:25 +02:00
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_clear_scheduled_hook', null, $hook, $args );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01: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 10:13:11 +01:00
|
|
|
$crons = _get_cron_array();
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
return 0;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-12-07 10:13:11 +01: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-05-01 04:05:23 +02:00
|
|
|
$results = array();
|
|
|
|
$key = md5( serialize( $args ) );
|
2013-12-07 10:13:11 +01:00
|
|
|
foreach ( $crons as $timestamp => $cron ) {
|
|
|
|
if ( isset( $cron[ $hook ][ $key ] ) ) {
|
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-05-01 04:05:23 +02:00
|
|
|
$results[] = wp_unschedule_event( $timestamp, $hook, $args );
|
2013-12-07 10:13:11 +01: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-05-01 04:05:23 +02:00
|
|
|
if ( in_array( false, $results, true ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return count( $results );
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
|
|
|
|
2017-06-30 02:22:44 +02:00
|
|
|
/**
|
2017-06-30 06:54:41 +02:00
|
|
|
* Unschedules all events attached to the hook.
|
2017-06-30 02:22:44 +02: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-05-01 04:05:23 +02: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-20 04:14:06 +01: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-05-01 04:05:23 +02:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2017-06-30 02:22:44 +02:00
|
|
|
* @since 4.9.0
|
2018-12-19 04:41:49 +01:00
|
|
|
* @since 5.1.0 Return value added to indicate success or failure.
|
2017-06-30 02:22:44 +02:00
|
|
|
*
|
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
2020-01-11 19:32:05 +01:00
|
|
|
* @return int|false On success an integer indicating number of events unscheduled (0 indicates no
|
2019-09-21 19:41:57 +02:00
|
|
|
* events were registered on the hook), false if unscheduling fails.
|
2017-06-30 02:22:44 +02:00
|
|
|
*/
|
|
|
|
function wp_unschedule_hook( $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-27 04:23:25 +02: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 06:06:48 +01: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-27 04:23:25 +02:00
|
|
|
*
|
2019-09-21 19:41:57 +02:00
|
|
|
* @param null|int|false $pre Value to return instead. Default null to continue unscheduling the hook.
|
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
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-27 04:23:25 +02:00
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_unschedule_hook', null, $hook );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2017-06-30 02:22:44 +02: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-05-01 04:05:23 +02:00
|
|
|
if ( empty( $crons ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-30 02:22:44 +02: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-05-01 04:05:23 +02:00
|
|
|
$results = array();
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
if ( ! empty( $crons[ $timestamp ][ $hook ] ) ) {
|
|
|
|
$results[] = count( $crons[ $timestamp ][ $hook ] );
|
|
|
|
}
|
2017-06-30 02:22:44 +02: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-05-01 04:05:23 +02:00
|
|
|
/*
|
|
|
|
* If the results are empty (zero events to unschedule), no attempt
|
|
|
|
* to update the cron array is required.
|
|
|
|
*/
|
|
|
|
if ( empty( $results ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( _set_cron_array( $crons ) ) {
|
|
|
|
return array_sum( $results );
|
|
|
|
}
|
|
|
|
return false;
|
2017-06-30 02:22:44 +02: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-27 04:23:25 +02:00
|
|
|
/**
|
|
|
|
* Retrieve a scheduled event.
|
|
|
|
*
|
2019-01-24 00:08:51 +01: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-27 04:23:25 +02:00
|
|
|
*
|
2018-12-30 06:06:48 +01: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-27 04:23:25 +02: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.
|
|
|
|
* @param int|null $timestamp Optional. Unix timestamp (UTC) of the event. If not specified, the next scheduled event is returned.
|
2020-01-11 19:32:05 +01: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-27 04:23:25 +02: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 06:06:48 +01: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-27 04:23:25 +02:00
|
|
|
*
|
2019-09-21 19:41:57 +02: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-24 00:08:51 +01: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-27 04:23:25 +02:00
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_get_scheduled_event', null, $hook, $args, $timestamp );
|
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2019-01-24 00:08:51 +01: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-27 04:23:25 +02:00
|
|
|
|
2019-01-24 00:08:51 +01: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-27 04:23:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-24 00:08:51 +01: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-27 04:23:25 +02: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 21:12:40 +02:00
|
|
|
/**
|
2016-08-26 11:22:30 +02:00
|
|
|
* Retrieve the next timestamp for an event.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
2017-11-22 16:16:47 +01: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.
|
2020-01-11 19:32:05 +01: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 21:12:40 +02:00
|
|
|
*/
|
2006-09-14 01:54:15 +02:00
|
|
|
function wp_next_scheduled( $hook, $args = array() ) {
|
2019-01-24 00:08:51 +01:00
|
|
|
$next_event = wp_get_scheduled_event( $hook, $args );
|
|
|
|
if ( ! $next_event ) {
|
|
|
|
return false;
|
2006-09-14 01:54:15 +02: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-27 04:23:25 +02:00
|
|
|
|
2019-01-24 00:08:51 +01:00
|
|
|
return $next_event->timestamp;
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
|
|
|
|
2008-08-01 07:00:07 +02:00
|
|
|
/**
|
2015-12-19 09:20:27 +01:00
|
|
|
* Sends a request to run cron through HTTP request that doesn't halt page loading.
|
2008-08-01 07:00:07 +02:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-19 04:41:49 +01:00
|
|
|
* @since 5.1.0 Return values added.
|
2015-12-19 09:20:27 +01:00
|
|
|
*
|
2016-08-26 11:22:30 +02: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-05-01 04:05:23 +02:00
|
|
|
* @return bool True if spawned, false if no events spawned.
|
2008-08-01 07:00:07 +02:00
|
|
|
*/
|
2012-09-23 18:57:21 +02:00
|
|
|
function spawn_cron( $gmt_time = 0 ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $gmt_time ) {
|
2012-09-23 18:57:21 +02:00
|
|
|
$gmt_time = microtime( true );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2009-02-07 14:32:34 +01:00
|
|
|
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2008-09-18 09:09:38 +02:00
|
|
|
|
2009-02-07 14:32:34 +01:00
|
|
|
/*
|
2016-08-26 11:22:30 +02:00
|
|
|
* Get the cron lock, which is a Unix timestamp of when the last cron was spawned
|
2015-05-25 08:25:25 +02: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-12-01 00:11:00 +01:00
|
|
|
$lock = get_transient( 'doing_cron' );
|
2009-02-07 14:32:34 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $lock > $gmt_time + 10 * MINUTE_IN_SECONDS ) {
|
2011-09-09 21:59:44 +02:00
|
|
|
$lock = 0;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2009-02-07 14:32:34 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Don't run if another process is currently running it or more than once every 60 sec.
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2009-02-07 14:32:34 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Sanity check.
|
2019-01-08 22:49:49 +01: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-05-01 04:05:23 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-06-27 08:04:27 +02:00
|
|
|
$keys = array_keys( $crons );
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2006-04-06 07:25:50 +02:00
|
|
|
|
2014-09-11 16:02:15 +02:00
|
|
|
if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
return false;
|
2014-09-11 16:02:15 +02:00
|
|
|
}
|
2008-09-18 09:09:38 +02:00
|
|
|
|
2012-09-23 18:57:21 +02:00
|
|
|
$doing_wp_cron = sprintf( '%.22F', $gmt_time );
|
2011-09-09 21:59:44 +02:00
|
|
|
set_transient( 'doing_cron', $doing_wp_cron );
|
2009-02-07 14:32:34 +01:00
|
|
|
|
|
|
|
ob_start();
|
2013-03-03 17:30:38 +01:00
|
|
|
wp_redirect( add_query_arg( 'doing_wp_cron', $doing_wp_cron, wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
|
2009-02-07 14:32:34 +01:00
|
|
|
echo ' ';
|
2008-09-18 09:09:38 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Flush any buffers and send the headers.
|
2019-07-09 07:45:58 +02:00
|
|
|
wp_ob_end_flush_all();
|
2009-02-07 14:32:34 +01:00
|
|
|
flush();
|
|
|
|
|
2019-07-09 07:45:58 +02: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-05-01 04:05:23 +02:00
|
|
|
return true;
|
2009-02-07 14:32:34 +01:00
|
|
|
}
|
2008-09-18 09:09:38 +02:00
|
|
|
|
2015-05-25 08:25:25 +02:00
|
|
|
// Set the cron lock with the current unix timestamp, when the cron is being spawned.
|
2012-09-23 18:57:21 +02:00
|
|
|
$doing_wp_cron = sprintf( '%.22F', $gmt_time );
|
2011-09-09 21:59:44 +02:00
|
|
|
set_transient( 'doing_cron', $doing_wp_cron );
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2013-11-19 06:01:11 +01:00
|
|
|
/**
|
2016-05-22 20:50:28 +02:00
|
|
|
* Filters the cron request arguments.
|
2013-11-19 06:01:11 +01:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
2016-01-14 18:30:28 +01:00
|
|
|
* @since 4.5.0 The `$doing_wp_cron` parameter was added.
|
2013-11-19 06:01:11 +01: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-20 00:53:19 +02:00
|
|
|
* @type bool $sslverify Whether SSL should be verified for the request. Default false.
|
2013-11-19 06:01:11 +01:00
|
|
|
* }
|
|
|
|
* }
|
2016-01-09 00:54:26 +01:00
|
|
|
* @param string $doing_wp_cron The unix timestamp of the cron lock.
|
2013-11-19 06:01:11 +01:00
|
|
|
*/
|
2017-12-01 00:11:00 +01:00
|
|
|
$cron_request = apply_filters(
|
2018-08-17 03:51:36 +02:00
|
|
|
'cron_request',
|
|
|
|
array(
|
2017-12-01 00:11:00 +01: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-17 03:51:36 +02:00
|
|
|
),
|
|
|
|
$doing_wp_cron
|
2017-12-01 00:11:00 +01:00
|
|
|
);
|
2012-07-20 17:15:22 +02: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-05-01 04:05:23 +02:00
|
|
|
$result = wp_remote_post( $cron_request['url'], $cron_request['args'] );
|
|
|
|
return ! is_wp_error( $result );
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
|
|
|
* Run scheduled callbacks or spawn cron for all scheduled events.
|
|
|
|
*
|
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-05-01 04:05:23 +02: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-20 04:14:06 +01: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-05-01 04:05:23 +02:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2008-09-04 21:12:40 +02:00
|
|
|
* @since 2.1.0
|
2018-12-19 04:41:49 +01:00
|
|
|
* @since 5.1.0 Return value added to indicate success or failure.
|
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-05-01 04:05:23 +02:00
|
|
|
*
|
|
|
|
* @return bool|int 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.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2006-03-07 22:43:59 +01:00
|
|
|
function wp_cron() {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Prevent infinite loops caused by lack of wp-cron.php.
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
return 0;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2007-01-30 14:06:56 +01:00
|
|
|
|
2019-01-08 22:49:49 +01: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-05-01 04:05:23 +02:00
|
|
|
return 0;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2006-06-10 22:43:49 +02:00
|
|
|
|
2012-09-23 18:57:21 +02:00
|
|
|
$gmt_time = microtime( true );
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
return 0;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2006-03-07 22:43:59 +01: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-05-01 04:05:23 +02:00
|
|
|
$results = array();
|
2006-04-06 07:25:50 +02:00
|
|
|
foreach ( $crons as $timestamp => $cronhooks ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $timestamp > $gmt_time ) {
|
|
|
|
break;
|
|
|
|
}
|
2008-08-06 22:31:54 +02:00
|
|
|
foreach ( (array) $cronhooks as $hook => $args ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( isset( $schedules[ $hook ]['callback'] ) && ! call_user_func( $schedules[ $hook ]['callback'] ) ) {
|
2006-03-07 22:43:59 +01:00
|
|
|
continue;
|
2017-12-01 00:11:00 +01: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-05-01 04:05:23 +02:00
|
|
|
$results[] = spawn_cron( $gmt_time );
|
2006-03-07 22:43:59 +01: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-05-01 04:05:23 +02:00
|
|
|
|
|
|
|
if ( in_array( false, $results, true ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return count( $results );
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
2016-08-26 11:22:30 +02:00
|
|
|
* Retrieve supported event recurrence schedules.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2020-01-12 12:20:04 +01: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 21:12:40 +02:00
|
|
|
*
|
2020-01-12 12:20:04 +01: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 21:12:40 +02:00
|
|
|
*
|
2020-01-12 12:20:04 +01:00
|
|
|
* The 'display' is the description. For the 'monthly' key, the 'display'
|
|
|
|
* would be `__( 'Once Monthly' )`.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2020-01-12 12:20:04 +01:00
|
|
|
* For your plugin, you will be passed an array. You can easily add your
|
2008-09-04 21:12:40 +02:00
|
|
|
* schedule by doing the following.
|
2014-11-24 05:58:22 +01:00
|
|
|
*
|
|
|
|
* // Filter parameter variable name is 'array'.
|
2020-01-12 12:20:04 +01:00
|
|
|
* $array['monthly'] = array(
|
|
|
|
* 'interval' => MONTH_IN_SECONDS,
|
|
|
|
* 'display' => __( 'Once Monthly' )
|
2014-11-24 05:58:22 +01:00
|
|
|
* );
|
|
|
|
*
|
2008-09-04 21:12:40 +02:00
|
|
|
* @since 2.1.0
|
2020-01-12 12:20:04 +01:00
|
|
|
* @since 5.4.0 The 'weekly' schedule was added.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2006-03-07 22:43:59 +01:00
|
|
|
function wp_get_schedules() {
|
|
|
|
$schedules = array(
|
2017-12-01 00:11:00 +01: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 12:20:04 +01:00
|
|
|
'weekly' => array(
|
2020-01-13 18:05:07 +01:00
|
|
|
'interval' => WEEK_IN_SECONDS,
|
2020-01-12 12:20:04 +01:00
|
|
|
'display' => __( 'Once Weekly' ),
|
|
|
|
),
|
2006-03-07 22:43:59 +01:00
|
|
|
);
|
2020-01-12 12:20:04 +01:00
|
|
|
|
2013-11-19 06:01:11 +01:00
|
|
|
/**
|
2016-05-22 20:50:28 +02:00
|
|
|
* Filters the non-default cron schedules.
|
2013-11-19 06:01:11 +01:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param array $new_schedules An array of non-default cron schedules. Default empty.
|
|
|
|
*/
|
2006-04-06 07:25:50 +02:00
|
|
|
return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
|
2006-03-07 22:43:59 +01:00
|
|
|
}
|
2006-04-06 07:25:50 +02:00
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
2016-08-26 11:22:30 +02:00
|
|
|
* Retrieve the recurrence schedule for an event.
|
|
|
|
*
|
|
|
|
* @see wp_get_schedules() for available schedules.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-30 06:06:48 +01:00
|
|
|
* @since 5.1.0 {@see 'get_schedule'} filter added.
|
2008-09-04 21:12:40 +02:00
|
|
|
*
|
2016-08-26 11:22:30 +02:00
|
|
|
* @param string $hook Action hook to identify the event.
|
|
|
|
* @param array $args Optional. Arguments passed to the event's callback function.
|
|
|
|
* @return string|false False, if no schedule. Schedule name on success.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2017-12-01 00:11:00 +01: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-27 04:23:25 +02:00
|
|
|
$schedule = false;
|
|
|
|
$event = wp_get_scheduled_event( $hook, $args );
|
|
|
|
|
|
|
|
if ( $event ) {
|
|
|
|
$schedule = $event->schedule;
|
2006-09-26 03:14:49 +02: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-27 04:23:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the schedule for a hook.
|
|
|
|
*
|
2018-12-30 06:06:48 +01: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-27 04:23:25 +02:00
|
|
|
*
|
|
|
|
* @param string|bool $schedule Schedule for the hook. False if not found.
|
|
|
|
* @param string $hook Action hook to execute when cron is run.
|
|
|
|
* @param array $args Optional. Arguments to pass to the hook's callback function.
|
|
|
|
*/
|
|
|
|
return apply_filters( 'get_schedule', $schedule, $hook, $args );
|
2006-09-26 03:14:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-08 22:49:49 +01: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();
|
|
|
|
|
|
|
|
if ( false === $crons ) {
|
|
|
|
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-14 01:54:15 +02:00
|
|
|
//
|
2020-01-29 01:45:18 +01:00
|
|
|
// Private functions.
|
2006-09-14 01:54:15 +02:00
|
|
|
//
|
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
|
|
|
* Retrieve cron info array option.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @access private
|
|
|
|
*
|
2020-01-11 19:32:05 +01:00
|
|
|
* @return array|false CRON info array.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2017-12-01 00:11:00 +01:00
|
|
|
function _get_cron_array() {
|
|
|
|
$cron = get_option( 'cron' );
|
|
|
|
if ( ! is_array( $cron ) ) {
|
2006-09-14 01:54:15 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2006-09-14 01:54:15 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! isset( $cron['version'] ) ) {
|
|
|
|
$cron = _upgrade_cron_array( $cron );
|
|
|
|
}
|
2006-09-14 01:54:15 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
unset( $cron['version'] );
|
2006-09-14 01:54:15 +02:00
|
|
|
|
|
|
|
return $cron;
|
|
|
|
}
|
|
|
|
|
2008-09-04 21:12:40 +02:00
|
|
|
/**
|
|
|
|
* Updates the CRON option with the new CRON array.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-30 05:51:51 +01:00
|
|
|
* @since 5.1.0 Return value modified to outcome of update_option().
|
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-05-01 04:05:23 +02:00
|
|
|
*
|
2008-09-04 21:12:40 +02:00
|
|
|
* @access private
|
|
|
|
*
|
2016-05-22 19:39:28 +02:00
|
|
|
* @param array $cron Cron info array from _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-05-01 04:05:23 +02:00
|
|
|
* @return bool True if cron array updated, false on failure.
|
2008-09-04 21:12:40 +02:00
|
|
|
*/
|
2017-12-01 00:11:00 +01:00
|
|
|
function _set_cron_array( $cron ) {
|
2006-09-14 01:54:15 +02:00
|
|
|
$cron['version'] = 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-05-01 04:05:23 +02:00
|
|
|
return update_option( 'cron', $cron );
|
2006-09-14 01:54:15 +02:00
|
|
|
}
|
|
|
|
|
2008-09-04 21:12:40 +02: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 19:39:28 +02:00
|
|
|
* @param array $cron Cron info array from _get_cron_array().
|
2008-09-04 21:12:40 +02:00
|
|
|
* @return array An upgraded Cron info array.
|
|
|
|
*/
|
2017-12-01 00:11:00 +01:00
|
|
|
function _upgrade_cron_array( $cron ) {
|
|
|
|
if ( isset( $cron['version'] ) && 2 == $cron['version'] ) {
|
2006-09-14 01:54:15 +02:00
|
|
|
return $cron;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2006-09-14 01:54:15 +02:00
|
|
|
|
|
|
|
$new_cron = array();
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
foreach ( (array) $cron as $timestamp => $hooks ) {
|
2008-08-06 22:31:54 +02:00
|
|
|
foreach ( (array) $hooks as $hook => $args ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$key = md5( serialize( $args['args'] ) );
|
|
|
|
$new_cron[ $timestamp ][ $hook ][ $key ] = $args;
|
2006-09-14 01:54:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$new_cron['version'] = 2;
|
|
|
|
update_option( 'cron', $new_cron );
|
|
|
|
return $new_cron;
|
2010-12-02 17:27:16 +01:00
|
|
|
}
|