2006-03-07 16:43:59 -05:00
|
|
|
<?php
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2016-08-26 05:22:30 -04:00
|
|
|
* WordPress Cron API
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2016-08-26 05:22:30 -04:00
|
|
|
* Schedules an event to run only once.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2022-10-11 05:02:14 -04:00
|
|
|
* Schedules a hook which will be triggered by WordPress at the specified UTC time.
|
2017-11-22 10:16:47 -05:00
|
|
|
* The action will trigger when someone visits your WordPress site if the scheduled
|
|
|
|
* time has passed.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2016-07-25 08:23:30 -04:00
|
|
|
* Note that scheduling an event to occur within 10 minutes of an existing event
|
2016-08-26 05:22:30 -04:00
|
|
|
* with the same action hook will be ignored unless you pass unique `$args` values
|
2016-07-25 08:23:30 -04:00
|
|
|
* for each scheduled event.
|
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* Use wp_next_scheduled() to prevent duplicate events.
|
|
|
|
*
|
|
|
|
* Use wp_schedule_event() to schedule a recurring event.
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_schedule_event'} filter added to short-circuit the function.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
*
|
2019-07-25 18:45:57 -04:00
|
|
|
* @link https://developer.wordpress.org/reference/functions/wp_schedule_single_event/
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) for when to next run the event.
|
|
|
|
* @param string $hook Action hook to execute when the event is run.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param array $args Optional. Array containing arguments to pass to the
|
2021-02-03 06:08:04 -05:00
|
|
|
* hook's callback function. Each value in the array
|
|
|
|
* is passed to the callback as an individual parameter.
|
|
|
|
* The array keys are ignored. Default empty array.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if event successfully scheduled. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_schedule_single_event( $timestamp, $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-06 22:39:23 -04:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_timestamp',
|
|
|
|
__( 'Event timestamp must be a valid Unix timestamp.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:39:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => false,
|
|
|
|
'args' => $args,
|
|
|
|
);
|
2017-11-22 10:16:47 -05:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
2023-08-18 13:29:20 -04:00
|
|
|
* Filter to override scheduling an event.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
|
|
|
* Returning a non-null value will short-circuit adding the event to the
|
|
|
|
* cron array, causing the function to return the filtered value instead.
|
|
|
|
*
|
|
|
|
* Both single events and recurring events are passed through this filter;
|
|
|
|
* single events have `$event->schedule` as false, whereas recurring events
|
2018-12-29 23:51:51 -05:00
|
|
|
* have this set to a recurrence from wp_get_schedules(). Recurring
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* events also have the integer recurrence interval set as `$event->interval`.
|
|
|
|
*
|
|
|
|
* For plugins replacing wp-cron, it is recommended you check for an
|
2018-12-29 23:51:51 -05:00
|
|
|
* identical event within ten minutes and apply the {@see 'schedule_event'}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* filter to check if another plugin has disallowed the event before scheduling.
|
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* Return true if the event was scheduled, false or a WP_Error if not.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
Code Modernization: Rename parameters that use reserved keywords in `phpunit/tests/cron.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$null` parameter to `$result` in `Tests_Cron::filter_pre_schedule_event_filter()`.
* Amends the `$pre` parameter of the `pre_schedule_event` filter for consistency.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960], [54961], [54962], [54964], [54965], [54969], [54970], [54971], [54972], [54996], [55000], [55011], [55013], [55014], [55015], [55016], [55017], [55020], [55021], [55023], [55027], [55028], [55034], [55036], [55037].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@55038
git-svn-id: http://core.svn.wordpress.org/trunk@54571 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-08 19:42:15 -05:00
|
|
|
* @param null|bool|WP_Error $result The value to return instead. Default null to continue adding the event.
|
2023-02-07 16:21:18 -05:00
|
|
|
* @param object $event {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* An object containing an event's data.
|
|
|
|
*
|
|
|
|
* @type string $hook Action hook to execute when the event is run.
|
|
|
|
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
|
|
|
|
* @type string|false $schedule How often the event should subsequently recur.
|
|
|
|
* @type array $args Array containing each separate argument to pass to the hook's callback function.
|
2023-02-07 16:21:18 -05:00
|
|
|
* @type int $interval Optional. The interval time in seconds for the schedule. Only present for recurring events.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* }
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_schedule_event', null, $event, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_schedule_event_false',
|
|
|
|
__( 'A plugin prevented the event from being scheduled.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2019-03-16 02:42:50 -04:00
|
|
|
/*
|
|
|
|
* Check for a duplicated event.
|
|
|
|
*
|
|
|
|
* Don't schedule an event if there's already an identical event
|
|
|
|
* within 10 minutes.
|
|
|
|
*
|
|
|
|
* When scheduling events within ten minutes of the current time,
|
|
|
|
* all past identical events are considered duplicates.
|
|
|
|
*
|
|
|
|
* When scheduling an event with a past timestamp (ie, before the
|
|
|
|
* current time) all events scheduled within the next ten minutes
|
|
|
|
* are considered duplicates.
|
|
|
|
*/
|
2021-10-18 08:51:58 -04:00
|
|
|
$crons = _get_cron_array();
|
|
|
|
|
2019-03-16 02:42:50 -04:00
|
|
|
$key = md5( serialize( $event->args ) );
|
|
|
|
$duplicate = false;
|
|
|
|
|
|
|
|
if ( $event->timestamp < time() + 10 * MINUTE_IN_SECONDS ) {
|
|
|
|
$min_timestamp = 0;
|
|
|
|
} else {
|
|
|
|
$min_timestamp = $event->timestamp - 10 * MINUTE_IN_SECONDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $event->timestamp < time() ) {
|
|
|
|
$max_timestamp = time() + 10 * MINUTE_IN_SECONDS;
|
|
|
|
} else {
|
|
|
|
$max_timestamp = $event->timestamp + 10 * MINUTE_IN_SECONDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $crons as $event_timestamp => $cron ) {
|
|
|
|
if ( $event_timestamp < $min_timestamp ) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2019-03-16 02:42:50 -04:00
|
|
|
if ( $event_timestamp > $max_timestamp ) {
|
|
|
|
break;
|
|
|
|
}
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2019-03-16 02:42:50 -04:00
|
|
|
if ( isset( $cron[ $event->hook ][ $key ] ) ) {
|
|
|
|
$duplicate = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $duplicate ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'duplicate_event',
|
|
|
|
__( 'A duplicate event already exists.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-19 00:01:11 -05:00
|
|
|
/**
|
2019-01-23 18:23:52 -05:00
|
|
|
* Modify an event before it is scheduled.
|
2013-11-19 00:01:11 -05:00
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
2023-02-07 16:21:18 -05:00
|
|
|
* @param object|false $event {
|
2020-05-03 15:38:08 -04:00
|
|
|
* An object containing an event's data, or boolean false to prevent the event from being scheduled.
|
2016-08-26 05:22:30 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @type string $hook Action hook to execute when the event is run.
|
|
|
|
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
|
|
|
|
* @type string|false $schedule How often the event should subsequently recur.
|
|
|
|
* @type array $args Array containing each separate argument to pass to the hook's callback function.
|
2023-02-07 16:21:18 -05:00
|
|
|
* @type int $interval Optional. The interval time in seconds for the schedule. Only present for recurring events.
|
2016-08-26 05:22:30 -04:00
|
|
|
* }
|
2013-11-19 00:01:11 -05:00
|
|
|
*/
|
|
|
|
$event = apply_filters( 'schedule_event', $event );
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// A plugin disallowed this event.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $event ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'schedule_event_false',
|
|
|
|
__( 'A plugin disallowed this event.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-10-18 16:50:35 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
|
|
|
|
'schedule' => $event->schedule,
|
|
|
|
'args' => $event->args,
|
|
|
|
);
|
|
|
|
uksort( $crons, 'strnatcasecmp' );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
return _set_cron_array( $crons, $wp_error );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2017-11-22 10:16:47 -05:00
|
|
|
* Schedules a recurring event.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* Schedules a hook which will be triggered by WordPress at the specified interval.
|
|
|
|
* The action will trigger when someone visits your WordPress site if the scheduled
|
|
|
|
* time has passed.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2023-11-11 04:28:30 -05:00
|
|
|
* Valid values for the recurrence are 'hourly', 'twicedaily', 'daily', and 'weekly'.
|
|
|
|
* These can be extended using the {@see 'cron_schedules'} filter in wp_get_schedules().
|
2009-04-08 16:16:59 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* Use wp_next_scheduled() to prevent duplicate events.
|
|
|
|
*
|
|
|
|
* Use wp_schedule_single_event() to schedule a non-recurring event.
|
2010-12-02 11:27:16 -05:00
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_schedule_event'} filter added to short-circuit the function.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
*
|
2019-07-25 18:45:57 -04:00
|
|
|
* @link https://developer.wordpress.org/reference/functions/wp_schedule_event/
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) for when to next run the event.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param string $recurrence How often the event should subsequently recur.
|
|
|
|
* See wp_get_schedules() for accepted values.
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param string $hook Action hook to execute when the event is run.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param array $args Optional. Array containing arguments to pass to the
|
2021-02-03 06:08:04 -05:00
|
|
|
* hook's callback function. Each value in the array
|
|
|
|
* is passed to the callback as an individual parameter.
|
|
|
|
* The array keys are ignored. Default empty array.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if event successfully scheduled. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-06 22:39:23 -04:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_timestamp',
|
|
|
|
__( 'Event timestamp must be a valid Unix timestamp.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:39:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:43:59 -05:00
|
|
|
$schedules = wp_get_schedules();
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $schedules[ $recurrence ] ) ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_schedule',
|
|
|
|
__( 'Event schedule does not exist.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:43:59 -05:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => $recurrence,
|
|
|
|
'args' => $args,
|
|
|
|
'interval' => $schedules[ $recurrence ]['interval'],
|
|
|
|
);
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
|
|
|
/** This filter is documented in wp-includes/cron.php */
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_schedule_event', null, $event, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_schedule_event_false',
|
|
|
|
__( 'A plugin prevented the event from being scheduled.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2013-11-19 00:01:11 -05:00
|
|
|
/** This filter is documented in wp-includes/cron.php */
|
|
|
|
$event = apply_filters( 'schedule_event', $event );
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// A plugin disallowed this event.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $event ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'schedule_event_false',
|
|
|
|
__( 'A plugin disallowed this event.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-10-18 16:50:35 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-10-18 16:50:35 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$key = md5( serialize( $event->args ) );
|
2010-10-18 16:50:35 -04:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
$crons = _get_cron_array();
|
Code Modernization: Check the return type of `_get_cron_array()` in `wp_schedule_event()`.
This fixes a "Deprecated: Automatic conversion of false to array is deprecated" warning on PHP 8.1.
In `wp_schedule_event()`, the cron info array is retrieved via a call to `_get_cron_array()`, but as the documentation (correctly) states, the return type of that function is `array|false`, where `false` is returned for a virgin site, with no cron jobs scheduled yet.
However, no type check is done on the return value, and the `wp_schedule_event()` function just blindly continues by assigning a value to a subkey of the `$crons` "array".
Fixed by adding validation for the returned value from `_get_cron_array()` and initializing an empty array if `false` was returned.
Reference: [https://developer.wordpress.org/reference/functions/_get_cron_array/ WordPress Developer Resources: _get_cron_array()]
Props jrf, hellofromTonya, lucatume, pbearne, iluy, pedromendonca, SergeyBiryukov.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51619
git-svn-id: http://core.svn.wordpress.org/trunk@51225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-08-16 11:23:57 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
|
|
|
|
'schedule' => $event->schedule,
|
|
|
|
'args' => $event->args,
|
|
|
|
'interval' => $event->interval,
|
|
|
|
);
|
|
|
|
uksort( $crons, 'strnatcasecmp' );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
return _set_cron_array( $crons, $wp_error );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2017-11-22 10:16:47 -05:00
|
|
|
* Reschedules a recurring event.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2022-10-11 05:02:14 -04:00
|
|
|
* Mainly for internal use, this takes the UTC timestamp of a previously run
|
2018-09-03 00:04:25 -04:00
|
|
|
* recurring event and reschedules it for its next run.
|
|
|
|
*
|
2018-12-29 23:51:51 -05:00
|
|
|
* To change upcoming scheduled events, use wp_schedule_event() to
|
2018-09-03 00:04:25 -04:00
|
|
|
* change the recurrence frequency.
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_reschedule_event'} filter added to short-circuit the function.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2018-09-03 00:04:25 -04:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) for when the event was scheduled.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param string $recurrence How often the event should subsequently recur.
|
|
|
|
* See wp_get_schedules() for accepted values.
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param string $hook Action hook to execute when the event is run.
|
2020-10-28 14:37:07 -04:00
|
|
|
* @param array $args Optional. Array containing arguments to pass to the
|
2021-02-03 06:08:04 -05:00
|
|
|
* hook's callback function. Each value in the array
|
|
|
|
* is passed to the callback as an individual parameter.
|
|
|
|
* The array keys are ignored. Default empty array.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if event successfully rescheduled. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-06 22:39:23 -04:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_timestamp',
|
|
|
|
__( 'Event timestamp must be a valid Unix timestamp.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:39:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:43:59 -05:00
|
|
|
$schedules = wp_get_schedules();
|
2017-11-30 18:11:00 -05:00
|
|
|
$interval = 0;
|
2006-04-06 01:25:50 -04:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
// First we try to get the interval from the schedule.
|
2014-08-01 16:57:16 -04:00
|
|
|
if ( isset( $schedules[ $recurrence ] ) ) {
|
|
|
|
$interval = $schedules[ $recurrence ]['interval'];
|
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
|
|
|
// Now we try to get it from the saved interval in case the schedule disappears.
|
|
|
|
if ( 0 === $interval ) {
|
|
|
|
$scheduled_event = wp_get_scheduled_event( $hook, $args, $timestamp );
|
2023-08-12 08:02:24 -04:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( $scheduled_event && isset( $scheduled_event->interval ) ) {
|
|
|
|
$interval = $scheduled_event->interval;
|
|
|
|
}
|
2014-08-01 16:57:16 -04:00
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => $recurrence,
|
|
|
|
'args' => $args,
|
|
|
|
'interval' => $interval,
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2023-08-18 13:29:20 -04:00
|
|
|
* Filter to override rescheduling of a recurring event.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
|
|
|
* 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
|
2022-10-11 05:02:14 -04:00
|
|
|
* rescheduled, false or a WP_Error if not.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue adding the event.
|
2023-02-07 16:21:18 -05:00
|
|
|
* @param object $event {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* An object containing an event's data.
|
|
|
|
*
|
2022-09-20 16:32:09 -04: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 $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.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
* }
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-20 07:11:03 -05:00
|
|
|
$pre = apply_filters( 'pre_reschedule_event', null, $event, $wp_error );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_reschedule_event_false',
|
|
|
|
__( 'A plugin prevented the event from being rescheduled.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Now we assume something is wrong and fail to schedule.
|
2023-08-12 08:02:24 -04:00
|
|
|
if ( 0 === $interval ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_schedule',
|
|
|
|
__( 'Event schedule does not exist.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-03-07 16:43:59 -05:00
|
|
|
return false;
|
2014-08-01 16:57:16 -04:00
|
|
|
}
|
2006-03-07 16:43:59 -05:00
|
|
|
|
2009-04-16 20:23:48 -04:00
|
|
|
$now = time();
|
|
|
|
|
2014-08-01 16:57:16 -04:00
|
|
|
if ( $timestamp >= $now ) {
|
2010-06-29 20:05:18 -04:00
|
|
|
$timestamp = $now + $interval;
|
2014-08-01 16:57:16 -04:00
|
|
|
} else {
|
|
|
|
$timestamp = $now + ( $interval - ( ( $now - $timestamp ) % $interval ) );
|
|
|
|
}
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2021-02-02 08:49:03 -05:00
|
|
|
return wp_schedule_event( $timestamp, $recurrence, $hook, $args, $wp_error );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Unschedules a previously scheduled event.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2023-01-31 12:50:12 -05:00
|
|
|
* The `$timestamp` and `$hook` parameters are required so that the event can be
|
2008-09-04 15:12:40 -04:00
|
|
|
* identified.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to boolean indicating success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_unschedule_event'} filter added to short-circuit the function.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param int $timestamp Unix timestamp (UTC) of the event.
|
|
|
|
* @param string $hook Action hook of the event.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify the
|
|
|
|
* event, so they should be the same as those used when originally scheduling the event.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return bool|WP_Error True if event successfully unscheduled. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_unschedule_event( $timestamp, $hook, $args = array(), $wp_error = false ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure timestamp is a positive integer.
|
2015-09-06 22:39:23 -04:00
|
|
|
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'invalid_timestamp',
|
|
|
|
__( 'Event timestamp must be a valid Unix timestamp.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-06 22:39:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
2023-08-18 13:29:20 -04:00
|
|
|
* Filter to override unscheduling of events.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
|
|
|
* 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
|
2022-10-11 05:02:14 -04:00
|
|
|
* unscheduled, false or a WP_Error if not.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue unscheduling the event.
|
|
|
|
* @param int $timestamp Timestamp for when to run the event.
|
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param array $args Arguments to pass to the hook's callback function.
|
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_unschedule_event', null, $timestamp, $hook, $args, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_unschedule_event_false',
|
|
|
|
__( 'A plugin prevented the event from being unscheduled.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2006-09-13 19:54:15 -04:00
|
|
|
$crons = _get_cron_array();
|
2017-11-30 18:11:00 -05:00
|
|
|
$key = md5( serialize( $args ) );
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
unset( $crons[ $timestamp ][ $hook ][ $key ] );
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $crons[ $timestamp ][ $hook ] ) ) {
|
|
|
|
unset( $crons[ $timestamp ][ $hook ] );
|
|
|
|
}
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $crons[ $timestamp ] ) ) {
|
|
|
|
unset( $crons[ $timestamp ] );
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
return _set_cron_array( $crons, $wp_error );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2017-06-30 00:54:41 -04:00
|
|
|
* Unschedules all events attached to the hook with the specified arguments.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2023-08-18 13:29:20 -04:00
|
|
|
* Warning: This function may return boolean false, but may also return a non-boolean
|
|
|
|
* value which evaluates to false. For information about casting to booleans see the
|
2020-01-19 22:14:06 -05:00
|
|
|
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value modified to indicate success or failure,
|
2018-12-29 23:51:51 -05:00
|
|
|
* {@see 'pre_clear_scheduled_hook'} filter added to short-circuit the function.
|
2021-02-03 05:58:07 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2021-02-03 05:58:07 -05:00
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify the
|
|
|
|
* event, so they should be the same as those used when originally scheduling the event.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
2021-02-03 05:58:07 -05:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @return int|false|WP_Error On success an integer indicating number of events unscheduled (0 indicates no
|
|
|
|
* events were registered with the hook and arguments combination), false or WP_Error
|
|
|
|
* if unscheduling one or more events fail.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_clear_scheduled_hook( $hook, $args = array(), $wp_error = false ) {
|
2023-07-09 17:48:22 -04:00
|
|
|
/*
|
|
|
|
* Backward compatibility.
|
|
|
|
* Previously, this function took the arguments as discrete vars rather than an array like the rest of the API.
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! is_array( $args ) ) {
|
2023-08-12 08:02:24 -04:00
|
|
|
_deprecated_argument(
|
|
|
|
__FUNCTION__,
|
|
|
|
'3.0.0',
|
|
|
|
__( 'This argument has changed to an array to match the behavior of the other cron functions.' )
|
|
|
|
);
|
|
|
|
|
2021-02-02 13:04:03 -05:00
|
|
|
$args = array_slice( func_get_args(), 1 ); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
|
2021-02-02 08:49:03 -05:00
|
|
|
$wp_error = false;
|
2009-12-24 06:12:04 -05:00
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
2023-08-18 13:29:20 -04:00
|
|
|
* Filter to override clearing a scheduled hook.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
|
|
|
* 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
|
2022-10-11 05:02:14 -04:00
|
|
|
* or a WP_Error if unscheduling one or more events fails.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|int|false|WP_Error $pre Value to return instead. Default null to continue unscheduling the event.
|
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param array $args Arguments to pass to the hook's callback function.
|
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_clear_scheduled_hook', null, $hook, $args, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_clear_scheduled_hook_false',
|
|
|
|
__( 'A plugin prevented the hook from being cleared.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* This logic duplicates wp_next_scheduled().
|
|
|
|
* It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing,
|
|
|
|
* and, wp_next_scheduled() returns the same schedule in an infinite loop.
|
|
|
|
*/
|
2013-12-07 04:13:11 -05:00
|
|
|
$crons = _get_cron_array();
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $crons ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-12-07 04:13:11 -05:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$results = array();
|
|
|
|
$key = md5( serialize( $args ) );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
2013-12-07 04:13:11 -05:00
|
|
|
foreach ( $crons as $timestamp => $cron ) {
|
|
|
|
if ( isset( $cron[ $hook ][ $key ] ) ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
$results[] = wp_unschedule_event( $timestamp, $hook, $args, true );
|
2013-12-07 04:13:11 -05:00
|
|
|
}
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
$errors = array_filter( $results, 'is_wp_error' );
|
|
|
|
$error = new WP_Error();
|
|
|
|
|
|
|
|
if ( $errors ) {
|
|
|
|
if ( $wp_error ) {
|
|
|
|
array_walk( $errors, array( $error, 'merge_from' ) );
|
|
|
|
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return count( $results );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2017-06-29 20:22:44 -04:00
|
|
|
/**
|
2017-06-30 00:54:41 -04:00
|
|
|
* Unschedules all events attached to the hook.
|
2017-06-29 20:22:44 -04:00
|
|
|
*
|
|
|
|
* Can be useful for plugins when deactivating to clean up the cron queue.
|
|
|
|
*
|
2023-08-18 13:29:20 -04:00
|
|
|
* Warning: This function may return boolean false, but may also return a non-boolean
|
|
|
|
* value which evaluates to false. For information about casting to booleans see the
|
2020-01-19 22:14:06 -05:00
|
|
|
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2017-06-29 20:22:44 -04:00
|
|
|
* @since 4.9.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value added to indicate success or failure.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
2017-06-29 20:22:44 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
|
|
|
* @return int|false|WP_Error On success an integer indicating number of events unscheduled (0 indicates no
|
|
|
|
* events were registered on the hook), false or WP_Error if unscheduling fails.
|
2017-06-29 20:22:44 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function wp_unschedule_hook( $hook, $wp_error = false ) {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
2023-08-18 13:29:20 -04:00
|
|
|
* Filter to override clearing all events attached to the hook.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
|
|
|
* 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
|
2024-05-02 09:19:14 -04:00
|
|
|
* unscheduled (zero if no events were registered with the hook). If unscheduling
|
|
|
|
* one or more events fails then return either a WP_Error object or false depending
|
|
|
|
* on the value of the `$wp_error` parameter.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-02-02 08:49:03 -05:00
|
|
|
* @param null|int|false|WP_Error $pre Value to return instead. Default null to continue unscheduling the hook.
|
|
|
|
* @param string $hook Action hook, the execution of which will be unscheduled.
|
|
|
|
* @param bool $wp_error Whether to return a WP_Error on failure.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
$pre = apply_filters( 'pre_unschedule_hook', null, $hook, $wp_error );
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
2021-02-02 08:49:03 -05:00
|
|
|
if ( $wp_error && false === $pre ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'pre_unschedule_hook_false',
|
|
|
|
__( 'A plugin prevented the hook from being cleared.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $wp_error && is_wp_error( $pre ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:22:44 -04:00
|
|
|
$crons = _get_cron_array();
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
if ( empty( $crons ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-29 20:22:44 -04:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$results = array();
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
foreach ( $crons as $timestamp => $args ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
if ( ! empty( $crons[ $timestamp ][ $hook ] ) ) {
|
|
|
|
$results[] = count( $crons[ $timestamp ][ $hook ] );
|
|
|
|
}
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2017-06-29 20:22:44 -04:00
|
|
|
unset( $crons[ $timestamp ][ $hook ] );
|
|
|
|
|
|
|
|
if ( empty( $crons[ $timestamp ] ) ) {
|
|
|
|
unset( $crons[ $timestamp ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
/*
|
|
|
|
* If the results are empty (zero events to unschedule), no attempt
|
|
|
|
* to update the cron array is required.
|
|
|
|
*/
|
|
|
|
if ( empty( $results ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
$set = _set_cron_array( $crons, $wp_error );
|
|
|
|
|
|
|
|
if ( true === $set ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return array_sum( $results );
|
|
|
|
}
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
return $set;
|
2017-06-29 20:22:44 -04:00
|
|
|
}
|
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Retrieves a scheduled event.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2023-01-31 12:50:12 -05:00
|
|
|
* Retrieves the full event object for a given event, if no timestamp is specified the next
|
2019-01-23 18:08:51 -05:00
|
|
|
* scheduled event is returned.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
|
|
|
* @param string $hook Action hook of the event.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify the
|
|
|
|
* event, so they should be the same as those used when originally scheduling the event.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
|
|
|
* @param int|null $timestamp Optional. Unix timestamp (UTC) of the event. If not specified, the next scheduled event
|
|
|
|
* is returned. Default null.
|
2023-02-07 16:21:18 -05:00
|
|
|
* @return object|false {
|
|
|
|
* The event object. False if the event does not exist.
|
|
|
|
*
|
|
|
|
* @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 Optional. The interval time in seconds for the schedule. Only present for recurring events.
|
|
|
|
* }
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
|
|
|
function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) {
|
|
|
|
/**
|
2023-08-18 13:29:20 -04:00
|
|
|
* Filter to override retrieving a scheduled event.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
|
|
|
* Returning a non-null value will short-circuit the normal process,
|
|
|
|
* returning the filtered value instead.
|
|
|
|
*
|
|
|
|
* Return false if the event does not exist, otherwise an event object
|
|
|
|
* should be returned.
|
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2019-09-21 13:41:57 -04:00
|
|
|
* @param null|false|object $pre Value to return instead. Default null to continue retrieving the event.
|
|
|
|
* @param string $hook Action hook of the event.
|
|
|
|
* @param array $args Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify
|
|
|
|
* the event.
|
2019-01-23 18:08:51 -05:00
|
|
|
* @param int|null $timestamp Unix timestamp (UTC) of the event. Null to retrieve next scheduled event.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_get_scheduled_event', null, $hook, $args, $timestamp );
|
2023-08-12 08:02:24 -04:00
|
|
|
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
if ( null !== $timestamp && ! is_numeric( $timestamp ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
$crons = _get_cron_array();
|
|
|
|
if ( empty( $crons ) ) {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
$key = md5( serialize( $args ) );
|
|
|
|
|
|
|
|
if ( ! $timestamp ) {
|
|
|
|
// Get next event.
|
|
|
|
$next = false;
|
|
|
|
foreach ( $crons as $timestamp => $cron ) {
|
|
|
|
if ( isset( $cron[ $hook ][ $key ] ) ) {
|
|
|
|
$next = $timestamp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
if ( ! $next ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$timestamp = $next;
|
|
|
|
} elseif ( ! isset( $crons[ $timestamp ][ $hook ][ $key ] ) ) {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$event = (object) array(
|
|
|
|
'hook' => $hook,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'schedule' => $crons[ $timestamp ][ $hook ][ $key ]['schedule'],
|
|
|
|
'args' => $args,
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( isset( $crons[ $timestamp ][ $hook ][ $key ]['interval'] ) ) {
|
|
|
|
$event->interval = $crons[ $timestamp ][ $hook ][ $key ]['interval'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Retrieves the next timestamp for an event.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
2017-11-22 10:16:47 -05:00
|
|
|
* @param string $hook Action hook of the event.
|
|
|
|
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
|
|
|
* Although not passed to a callback, these arguments are used to uniquely identify the
|
|
|
|
* event, so they should be the same as those used when originally scheduling the event.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
2020-01-11 13:32:05 -05:00
|
|
|
* @return int|false The Unix timestamp of the next time the event will occur. False if the event doesn't exist.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2006-09-13 19:54:15 -04:00
|
|
|
function wp_next_scheduled( $hook, $args = array() ) {
|
2019-01-23 18:08:51 -05:00
|
|
|
$next_event = wp_get_scheduled_event( $hook, $args );
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
if ( ! $next_event ) {
|
|
|
|
return false;
|
2006-09-13 19:54:15 -04:00
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
2019-01-23 18:08:51 -05:00
|
|
|
return $next_event->timestamp;
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-08-01 01:00:07 -04:00
|
|
|
/**
|
2015-12-19 03:20:27 -05:00
|
|
|
* Sends a request to run cron through HTTP request that doesn't halt page loading.
|
2008-08-01 01:00:07 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return values added.
|
2015-12-19 03:20:27 -05:00
|
|
|
*
|
2016-08-26 05:22:30 -04:00
|
|
|
* @param int $gmt_time Optional. Unix timestamp (UTC). Default 0 (current time is used).
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* @return bool True if spawned, false if no events spawned.
|
2008-08-01 01:00:07 -04:00
|
|
|
*/
|
2012-09-23 12:57:21 -04:00
|
|
|
function spawn_cron( $gmt_time = 0 ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $gmt_time ) {
|
2012-09-23 12:57:21 -04:00
|
|
|
$gmt_time = microtime( true );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2009-02-07 08:32:34 -05:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( defined( 'DOING_CRON' ) || isset( $_GET['doing_wp_cron'] ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2008-09-18 03:09:38 -04:00
|
|
|
|
2009-02-07 08:32:34 -05:00
|
|
|
/*
|
2016-08-26 05:22:30 -04:00
|
|
|
* Get the cron lock, which is a Unix timestamp of when the last cron was spawned
|
2015-05-25 02:25:25 -04:00
|
|
|
* and has not finished running.
|
|
|
|
*
|
|
|
|
* Multiple processes on multiple web servers can run this code concurrently,
|
|
|
|
* this lock attempts to make spawning as atomic as possible.
|
|
|
|
*/
|
2023-09-11 01:27:22 -04:00
|
|
|
$lock = (float) get_transient( 'doing_cron' );
|
2009-02-07 08:32:34 -05:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $lock > $gmt_time + 10 * MINUTE_IN_SECONDS ) {
|
2011-09-09 15:59:44 -04:00
|
|
|
$lock = 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2009-02-07 08:32:34 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Don't run if another process is currently running it or more than once every 60 sec.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $lock + WP_CRON_LOCK_TIMEOUT > $gmt_time ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2009-02-07 08:32:34 -05:00
|
|
|
|
Docs: Replace "sanity" with "confidence" for inclusive language.
The phrase "sanity check" unnecessarily references mental health. It's an old phrase used to denote an extra step in verifying code works as expected.
“The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included.”
While "sanity check" is a well-known phrase with a specific meaning, "confidence check" is a direct replacement that is more clear of its intent while being more inclusive.
Words matter.
Follow-up to [49216], [46271], [40583], [38832], [38637], [37409], [33359], [32162], [30346], [30345], [30238], [30055], [29902], [28763], [26141], [25002], [22227], [13428], [12148], [11025], [8927].
Props dartiss, hellofromTonya.
Fixes #60187.
Built from https://develop.svn.wordpress.org/trunk@57239
git-svn-id: http://core.svn.wordpress.org/trunk@56745 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-03 16:59:19 -05:00
|
|
|
// Confidence check.
|
2019-01-08 16:49:49 -05:00
|
|
|
$crons = wp_get_ready_cron_jobs();
|
|
|
|
if ( empty( $crons ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-06-27 02:04:27 -04:00
|
|
|
$keys = array_keys( $crons );
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2014-09-11 10:02:15 -04:00
|
|
|
if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( 'GET' !== $_SERVER['REQUEST_METHOD'] || defined( 'DOING_AJAX' ) || defined( 'XMLRPC_REQUEST' ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return false;
|
2014-09-11 10:02:15 -04:00
|
|
|
}
|
2008-09-18 03:09:38 -04:00
|
|
|
|
2012-09-23 12:57:21 -04:00
|
|
|
$doing_wp_cron = sprintf( '%.22F', $gmt_time );
|
2011-09-09 15:59:44 -04:00
|
|
|
set_transient( 'doing_cron', $doing_wp_cron );
|
2009-02-07 08:32:34 -05:00
|
|
|
|
|
|
|
ob_start();
|
2013-03-03 11:30:38 -05:00
|
|
|
wp_redirect( add_query_arg( 'doing_wp_cron', $doing_wp_cron, wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
|
2009-02-07 08:32:34 -05:00
|
|
|
echo ' ';
|
2008-09-18 03:09:38 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Flush any buffers and send the headers.
|
2019-07-09 01:45:58 -04:00
|
|
|
wp_ob_end_flush_all();
|
2009-02-07 08:32:34 -05:00
|
|
|
flush();
|
|
|
|
|
Coding Standards: Replace `include_once` with `require_once` for required files.
Per [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#writing-include-require-statements WordPress PHP coding standards], it is ''strongly recommended'' to use `require[_once]` for unconditional includes. When using `include[_once]`, PHP will throw a warning when the file is not found but will continue execution, which will almost certainly lead to other errors/warnings/notices being thrown if your application depends on the file loaded, potentially leading to security leaks. For that reason, `require[_once]` is generally the better choice as it will throw a `Fatal Error` if the file cannot be found.
Follow-up to [1674], [1812], [1964], [6779], [8540], [10521], [11005], [11911], [16065], [16149], [25421], [25466], [25823], [37714], [42981], [45448], [47198], [54276], [55633].
Props kausaralm, SergeyBiryukov.
See #57839.
Built from https://develop.svn.wordpress.org/trunk@55641
git-svn-id: http://core.svn.wordpress.org/trunk@55153 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-04-09 07:57:22 -04:00
|
|
|
require_once ABSPATH . 'wp-cron.php';
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return true;
|
2009-02-07 08:32:34 -05:00
|
|
|
}
|
2008-09-18 03:09:38 -04:00
|
|
|
|
2015-05-25 02:25:25 -04:00
|
|
|
// Set the cron lock with the current unix timestamp, when the cron is being spawned.
|
2012-09-23 12:57:21 -04:00
|
|
|
$doing_wp_cron = sprintf( '%.22F', $gmt_time );
|
2011-09-09 15:59:44 -04:00
|
|
|
set_transient( 'doing_cron', $doing_wp_cron );
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2013-11-19 00:01:11 -05:00
|
|
|
/**
|
2016-05-22 14:50:28 -04:00
|
|
|
* Filters the cron request arguments.
|
2013-11-19 00:01:11 -05:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
2016-01-14 12:30:28 -05:00
|
|
|
* @since 4.5.0 The `$doing_wp_cron` parameter was added.
|
2013-11-19 00:01:11 -05:00
|
|
|
*
|
|
|
|
* @param array $cron_request_array {
|
|
|
|
* An array of cron request URL arguments.
|
|
|
|
*
|
|
|
|
* @type string $url The cron request URL.
|
|
|
|
* @type int $key The 22 digit GMT microtime.
|
|
|
|
* @type array $args {
|
|
|
|
* An array of cron request arguments.
|
|
|
|
*
|
|
|
|
* @type int $timeout The request timeout in seconds. Default .01 seconds.
|
|
|
|
* @type bool $blocking Whether to set blocking for the request. Default false.
|
2014-06-19 18:53:19 -04:00
|
|
|
* @type bool $sslverify Whether SSL should be verified for the request. Default false.
|
2013-11-19 00:01:11 -05:00
|
|
|
* }
|
|
|
|
* }
|
2016-01-08 18:54:26 -05:00
|
|
|
* @param string $doing_wp_cron The unix timestamp of the cron lock.
|
2013-11-19 00:01:11 -05:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
$cron_request = apply_filters(
|
2018-08-16 21:51:36 -04:00
|
|
|
'cron_request',
|
|
|
|
array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'url' => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ),
|
|
|
|
'key' => $doing_wp_cron,
|
|
|
|
'args' => array(
|
|
|
|
'timeout' => 0.01,
|
|
|
|
'blocking' => false,
|
|
|
|
/** This filter is documented in wp-includes/class-wp-http-streams.php */
|
|
|
|
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
|
|
|
|
),
|
2018-08-16 21:51:36 -04:00
|
|
|
),
|
|
|
|
$doing_wp_cron
|
2017-11-30 18:11:00 -05:00
|
|
|
);
|
2012-07-20 11:15:22 -04:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$result = wp_remote_post( $cron_request['url'], $cron_request['args'] );
|
2023-08-12 08:02:24 -04:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return ! is_wp_error( $result );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Registers _wp_cron() to run on the {@see 'wp_loaded'} action.
|
Cron API: Run alternative wp-cron later, do not run on archived blogs.
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 22:10:08 -05:00
|
|
|
*
|
|
|
|
* If the {@see 'wp_loaded'} action has already fired, this function calls
|
|
|
|
* _wp_cron() directly.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* Warning: This function may return Boolean FALSE, but may also return a non-Boolean
|
|
|
|
* value which evaluates to FALSE. For information about casting to booleans see the
|
2020-01-19 22:14:06 -05:00
|
|
|
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2018-12-18 22:41:49 -05:00
|
|
|
* @since 5.1.0 Return value added to indicate success or failure.
|
Cron API: Run alternative wp-cron later, do not run on archived blogs.
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 22:10:08 -05:00
|
|
|
* @since 5.7.0 Functionality moved to _wp_cron() to which this becomes a wrapper.
|
|
|
|
*
|
2023-08-18 13:29:20 -04:00
|
|
|
* @return false|int|void On success an integer indicating number of events spawned (0 indicates no
|
|
|
|
* events needed to be spawned), false if spawning fails for one or more events or
|
|
|
|
* void if the function registered _wp_cron() to run on the action.
|
Cron API: Run alternative wp-cron later, do not run on archived blogs.
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 22:10:08 -05:00
|
|
|
*/
|
|
|
|
function wp_cron() {
|
|
|
|
if ( did_action( 'wp_loaded' ) ) {
|
|
|
|
return _wp_cron();
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'wp_loaded', '_wp_cron', 20 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Runs scheduled callbacks or spawns cron for all scheduled events.
|
Cron API: Run alternative wp-cron later, do not run on archived blogs.
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 22:10:08 -05:00
|
|
|
*
|
|
|
|
* Warning: This function may return Boolean FALSE, but may also return a non-Boolean
|
|
|
|
* value which evaluates to FALSE. For information about casting to booleans see the
|
|
|
|
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
|
|
|
|
* the `===` operator for testing the return value of this function.
|
|
|
|
*
|
|
|
|
* @since 5.7.0
|
|
|
|
* @access private
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
*
|
2021-01-04 12:18:04 -05:00
|
|
|
* @return int|false On success an integer indicating number of events spawned (0 indicates no
|
2021-01-03 17:04:04 -05:00
|
|
|
* events needed to be spawned), false if spawning fails for one or more events.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
Cron API: Run alternative wp-cron later, do not run on archived blogs.
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes #20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-01 22:10:08 -05:00
|
|
|
function _wp_cron() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Prevent infinite loops caused by lack of wp-cron.php.
|
2023-08-12 08:02:24 -04:00
|
|
|
if ( str_contains( $_SERVER['REQUEST_URI'], '/wp-cron.php' )
|
|
|
|
|| ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON )
|
|
|
|
) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2007-01-30 08:06:56 -05:00
|
|
|
|
2019-01-08 16:49:49 -05:00
|
|
|
$crons = wp_get_ready_cron_jobs();
|
|
|
|
if ( empty( $crons ) ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-06-10 16:43:49 -04:00
|
|
|
|
2012-09-23 12:57:21 -04:00
|
|
|
$gmt_time = microtime( true );
|
2017-11-30 18:11:00 -05:00
|
|
|
$keys = array_keys( $crons );
|
|
|
|
if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return 0;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-03-07 16:43:59 -05:00
|
|
|
|
|
|
|
$schedules = wp_get_schedules();
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$results = array();
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2006-04-06 01:25:50 -04:00
|
|
|
foreach ( $crons as $timestamp => $cronhooks ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $timestamp > $gmt_time ) {
|
|
|
|
break;
|
|
|
|
}
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $cronhooks as $hook => $args ) {
|
2023-08-12 08:02:24 -04:00
|
|
|
if ( isset( $schedules[ $hook ]['callback'] )
|
|
|
|
&& ! call_user_func( $schedules[ $hook ]['callback'] )
|
|
|
|
) {
|
2006-03-07 16:43:59 -05:00
|
|
|
continue;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2023-08-12 08:02:24 -04:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
$results[] = spawn_cron( $gmt_time );
|
2006-03-07 16:43:59 -05:00
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
}
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
|
|
|
|
if ( in_array( false, $results, true ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-08-12 08:02:24 -04:00
|
|
|
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
return count( $results );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Retrieves supported event recurrence schedules.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2020-01-12 06:20:04 -05:00
|
|
|
* The default supported recurrences are 'hourly', 'twicedaily', 'daily', and 'weekly'.
|
|
|
|
* A plugin may add more by hooking into the {@see 'cron_schedules'} filter.
|
|
|
|
* The filter accepts an array of arrays. The outer array has a key that is the name
|
|
|
|
* of the schedule, for example 'monthly'. The value is an array with two keys,
|
|
|
|
* one is 'interval' and the other is 'display'.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2020-01-12 06:20:04 -05:00
|
|
|
* The 'interval' is a number in seconds of when the cron job should run.
|
2024-05-02 09:19:14 -04:00
|
|
|
* So for 'hourly' the time is `HOUR_IN_SECONDS` (`60 * 60` or `3600`). For 'monthly',
|
|
|
|
* the value would be `MONTH_IN_SECONDS` (`30 * 24 * 60 * 60` or `2592000`).
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2020-01-12 06:20:04 -05:00
|
|
|
* The 'display' is the description. For the 'monthly' key, the 'display'
|
|
|
|
* would be `__( 'Once Monthly' )`.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2024-05-02 09:19:14 -04:00
|
|
|
* For your plugin, you will be passed an array. You can add your
|
|
|
|
* schedule by doing the following:
|
2014-11-23 23:58:22 -05:00
|
|
|
*
|
|
|
|
* // Filter parameter variable name is 'array'.
|
2020-01-12 06:20:04 -05:00
|
|
|
* $array['monthly'] = array(
|
|
|
|
* 'interval' => MONTH_IN_SECONDS,
|
|
|
|
* 'display' => __( 'Once Monthly' )
|
2014-11-23 23:58:22 -05:00
|
|
|
* );
|
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @since 2.1.0
|
2020-01-12 06:20:04 -05:00
|
|
|
* @since 5.4.0 The 'weekly' schedule was added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2023-01-31 12:50:12 -05:00
|
|
|
* @return array {
|
|
|
|
* The array of cron schedules keyed by the schedule name.
|
|
|
|
*
|
|
|
|
* @type array ...$0 {
|
|
|
|
* Cron schedule information.
|
|
|
|
*
|
|
|
|
* @type int $interval The schedule interval in seconds.
|
|
|
|
* @type string $display The schedule display name.
|
|
|
|
* }
|
|
|
|
* }
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2006-03-07 16:43:59 -05:00
|
|
|
function wp_get_schedules() {
|
|
|
|
$schedules = array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'hourly' => array(
|
|
|
|
'interval' => HOUR_IN_SECONDS,
|
|
|
|
'display' => __( 'Once Hourly' ),
|
|
|
|
),
|
|
|
|
'twicedaily' => array(
|
|
|
|
'interval' => 12 * HOUR_IN_SECONDS,
|
|
|
|
'display' => __( 'Twice Daily' ),
|
|
|
|
),
|
|
|
|
'daily' => array(
|
|
|
|
'interval' => DAY_IN_SECONDS,
|
|
|
|
'display' => __( 'Once Daily' ),
|
|
|
|
),
|
2020-01-12 06:20:04 -05:00
|
|
|
'weekly' => array(
|
2020-01-13 12:05:07 -05:00
|
|
|
'interval' => WEEK_IN_SECONDS,
|
2020-01-12 06:20:04 -05:00
|
|
|
'display' => __( 'Once Weekly' ),
|
|
|
|
),
|
2006-03-07 16:43:59 -05:00
|
|
|
);
|
2020-01-12 06:20:04 -05:00
|
|
|
|
2013-11-19 00:01:11 -05:00
|
|
|
/**
|
2016-05-22 14:50:28 -04:00
|
|
|
* Filters the non-default cron schedules.
|
2013-11-19 00:01:11 -05:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
2023-01-31 12:50:12 -05:00
|
|
|
* @param array $new_schedules {
|
|
|
|
* An array of non-default cron schedules keyed by the schedule name. Default empty array.
|
|
|
|
*
|
|
|
|
* @type array ...$0 {
|
|
|
|
* Cron schedule information.
|
|
|
|
*
|
|
|
|
* @type int $interval The schedule interval in seconds.
|
|
|
|
* @type string $display The schedule display name.
|
|
|
|
* }
|
|
|
|
* }
|
2013-11-19 00:01:11 -05:00
|
|
|
*/
|
2006-04-06 01:25:50 -04:00
|
|
|
return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
|
2006-03-07 16:43:59 -05:00
|
|
|
}
|
2006-04-06 01:25:50 -04:00
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Retrieves the name of the recurrence schedule for an event.
|
2016-08-26 05:22:30 -04:00
|
|
|
*
|
|
|
|
* @see wp_get_schedules() for available schedules.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0 {@see 'get_schedule'} filter added.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2016-08-26 05:22:30 -04:00
|
|
|
* @param string $hook Action hook to identify the event.
|
2020-07-23 17:11:05 -04:00
|
|
|
* @param array $args Optional. Arguments passed to the event's callback function.
|
2021-02-03 06:08:04 -05:00
|
|
|
* Default empty array.
|
2021-01-15 15:08:07 -05:00
|
|
|
* @return string|false Schedule name on success, false if no schedule.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
function wp_get_schedule( $hook, $args = array() ) {
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
$schedule = false;
|
|
|
|
$event = wp_get_scheduled_event( $hook, $args );
|
|
|
|
|
|
|
|
if ( $event ) {
|
|
|
|
$schedule = $event->schedule;
|
2006-09-25 21:14:49 -04:00
|
|
|
}
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
|
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Filters the schedule name for a hook.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2018-12-30 00:06:48 -05:00
|
|
|
* @since 5.1.0
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*
|
2021-01-03 17:04:04 -05:00
|
|
|
* @param string|false $schedule Schedule for the hook. False if not found.
|
|
|
|
* @param string $hook Action hook to execute when cron is run.
|
2021-02-03 06:08:04 -05:00
|
|
|
* @param array $args Arguments to pass to the hook's callback function.
|
Cron: Add hooks and a function to allow hijacking cron implementation.
This allows sites with a large cron option or a custom cron implementation to hijack the cron option to store cron data using custom functionality.
`wp_get_scheduled_event()` is new function to retrieve the event object for a given event based on the hook name, arguments and timestamp. If no timestamp is specified the next occurence is returned.
Preflight filters are added to all functions that read from or modify the cron option: `pre_schedule_event`, `pre_reschedule_event`, `pre_unschedule_event`, `pre_clear_scheduled_hook`, `pre_unschedule_hook`, `pre_get_scheduled_event` and `pre_next_scheduled`.
Additionally, the post scheduling hooks `next_scheduled` and `get_schedule` to allow plugins to modify an event after retrieving it from WordPress.
Props rmccue, DavidAnderson, ethitter, peterwilsoncc.
Fixes #32656.
Built from https://develop.svn.wordpress.org/trunk@43540
git-svn-id: http://core.svn.wordpress.org/trunk@43369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-07-26 22:23:25 -04:00
|
|
|
*/
|
|
|
|
return apply_filters( 'get_schedule', $schedule, $hook, $args );
|
2006-09-25 21:14:49 -04:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:49:49 -05:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Retrieves cron jobs ready to be run.
|
2019-01-08 16:49:49 -05:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2021-11-23 16:37:01 -05:00
|
|
|
* @return array[] Array of cron job arrays ready to be run.
|
2019-01-08 16:49:49 -05:00
|
|
|
*/
|
|
|
|
function wp_get_ready_cron_jobs() {
|
|
|
|
/**
|
2023-08-18 13:29:20 -04:00
|
|
|
* Filter to override retrieving ready cron jobs.
|
2019-01-08 16:49:49 -05:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2021-11-23 16:37:01 -05:00
|
|
|
* @param null|array[] $pre Array of ready cron tasks to return instead. Default null
|
|
|
|
* to continue using results from _get_cron_array().
|
2019-01-08 16:49:49 -05:00
|
|
|
*/
|
|
|
|
$pre = apply_filters( 'pre_get_ready_cron_jobs', null );
|
2022-09-08 21:53:11 -04:00
|
|
|
|
2019-01-08 16:49:49 -05:00
|
|
|
if ( null !== $pre ) {
|
|
|
|
return $pre;
|
|
|
|
}
|
|
|
|
|
Coding Standards: Various alignment fixes from `composer format`.
Follow up to [53874], [54097], [54110], [54155], [54162], [54184].
See #39210, #55443, #56288, #56092, #56408, #56467, #55881.
Built from https://develop.svn.wordpress.org/trunk@54210
git-svn-id: http://core.svn.wordpress.org/trunk@53769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-19 15:51:09 -04:00
|
|
|
$crons = _get_cron_array();
|
2019-01-08 16:49:49 -05:00
|
|
|
$gmt_time = microtime( true );
|
Coding Standards: Various alignment fixes from `composer format`.
Follow up to [53874], [54097], [54110], [54155], [54162], [54184].
See #39210, #55443, #56288, #56092, #56408, #56467, #55881.
Built from https://develop.svn.wordpress.org/trunk@54210
git-svn-id: http://core.svn.wordpress.org/trunk@53769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-19 15:51:09 -04:00
|
|
|
$results = array();
|
2022-09-08 21:53:11 -04:00
|
|
|
|
2019-01-08 16:49:49 -05:00
|
|
|
foreach ( $crons as $timestamp => $cronhooks ) {
|
|
|
|
if ( $timestamp > $gmt_time ) {
|
|
|
|
break;
|
|
|
|
}
|
2022-09-08 21:53:11 -04:00
|
|
|
|
2019-01-08 16:49:49 -05:00
|
|
|
$results[ $timestamp ] = $cronhooks;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
2006-09-13 19:54:15 -04:00
|
|
|
//
|
2020-01-28 19:45:18 -05:00
|
|
|
// Private functions.
|
2006-09-13 19:54:15 -04:00
|
|
|
//
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Retrieves cron info array option.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2022-10-12 07:53:15 -04:00
|
|
|
* @since 6.1.0 Return type modified to consistently return an array.
|
2008-09-04 15:12:40 -04:00
|
|
|
* @access private
|
|
|
|
*
|
2022-07-28 23:34:13 -04:00
|
|
|
* @return array[] Array of cron events.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
function _get_cron_array() {
|
|
|
|
$cron = get_option( 'cron' );
|
|
|
|
if ( ! is_array( $cron ) ) {
|
2022-07-28 23:34:13 -04:00
|
|
|
return array();
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-09-13 19:54:15 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $cron['version'] ) ) {
|
|
|
|
$cron = _upgrade_cron_array( $cron );
|
|
|
|
}
|
2006-09-13 19:54:15 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
unset( $cron['version'] );
|
2006-09-13 19:54:15 -04:00
|
|
|
|
|
|
|
return $cron;
|
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2021-02-02 08:49:03 -05:00
|
|
|
* Updates the cron option with the new cron array.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
2018-12-29 23:51:51 -05:00
|
|
|
* @since 5.1.0 Return value modified to outcome of update_option().
|
2021-02-02 08:49:03 -05:00
|
|
|
* @since 5.7.0 The `$wp_error` parameter was added.
|
Cron API: Return meaningful values from cron functions.
Return values added to Cron API functions to indicate outcome:
* `wp_schedule_single_event()`, `wp_schedule_event()`, `wp_reschedule_event()` and `wp_unschedule_event()`: boolean indicating success or failure,
* `wp_clear_scheduled_hook()`: integer indicating number of jobs cleared (zero or more), `false` if one or more jobs fail to clear,
* `wp_unschedule_hook()`: integer indicating number of jobs cleared (zero or more), `false` if the jobs fail to clear,
* `spawn_cron()`: boolean indicating whether job spawned,
* `wp_cron()`: integer indicating number of jobs spawned (zero or more), `false` if one or more jobs fail to spawned,
* `_set_cron_array()`: boolean outcome of `update_option()`.
Props evansolomon, jrf, peterwilsoncc, pento for code review.
Fixes #21072.
Built from https://develop.svn.wordpress.org/trunk@43050
git-svn-id: http://core.svn.wordpress.org/trunk@42879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-04-30 22:05:23 -04:00
|
|
|
*
|
2008-09-04 15:12:40 -04:00
|
|
|
* @access private
|
|
|
|
*
|
2021-11-23 16:37:01 -05:00
|
|
|
* @param array[] $cron Array of cron info arrays from _get_cron_array().
|
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
|
2021-02-02 08:49:03 -05:00
|
|
|
* @return bool|WP_Error True if cron array updated. False or WP_Error on failure.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2021-02-02 08:49:03 -05:00
|
|
|
function _set_cron_array( $cron, $wp_error = false ) {
|
2021-08-30 11:20:56 -04:00
|
|
|
if ( ! is_array( $cron ) ) {
|
|
|
|
$cron = array();
|
|
|
|
}
|
|
|
|
|
2006-09-13 19:54:15 -04:00
|
|
|
$cron['version'] = 2;
|
2023-08-12 08:02:24 -04:00
|
|
|
|
Options, Meta APIs: Explicitly pass `$autoload` parameter to when potentially adding new options.
It is recommended that for every option it is explicitly set whether to autoload it or not. This changeset updates relevant `update_option()` and `add_option()` calls.
Note that the `$autoload` parameter is only needed for `update_option()` if the option is potentially not present yet, i.e. the call will pass through to `add_option()`. Since WordPress core adds the majority of its options to the database during installation, only `update_option()` calls for dynamically added options need to be modified, which is what this changeset does.
As part of revisiting the autoload values for dynamically added WordPress core options, this changeset modifies some options to no longer be autoloaded, since they are only accessed in a few specific places that are not relevant for a regular request. These options are:
* `recently_activated`
* `_wp_suggested_policy_text_has_changed`
* `{upgradeLock}.lock`
* `dashboard_widget_options`
* `ftp_credentials`
* `adminhash`
* `nav_menu_options`
* `wp_force_deactivated_plugins`
* `delete_blog_hash`
* `allowedthemes`
* `{sessionId}_paused_extensions`
* `recovery_keys`
* `https_detection_errors`
* `fresh_site`
An upgrade routine is present as well that sets those options to no longer autoload for existing sites.
Props pbearne, flixos90, mukesh27, swissspidy, SergeyBiryukov, joemcgill, adamsilverstein.
Fixes #61103.
Built from https://develop.svn.wordpress.org/trunk@58975
git-svn-id: http://core.svn.wordpress.org/trunk@58371 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-09-03 14:19:14 -04:00
|
|
|
$result = update_option( 'cron', $cron, true );
|
2021-02-02 08:49:03 -05:00
|
|
|
|
|
|
|
if ( $wp_error && ! $result ) {
|
|
|
|
return new WP_Error(
|
|
|
|
'could_not_set',
|
|
|
|
__( 'The cron event list could not be saved.' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
2006-09-13 19:54:15 -04:00
|
|
|
}
|
|
|
|
|
2008-09-04 15:12:40 -04:00
|
|
|
/**
|
2023-01-31 12:50:12 -05:00
|
|
|
* Upgrades a cron info array.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
2022-08-11 10:11:08 -04:00
|
|
|
* This function upgrades the cron info array to version 2.
|
2008-09-04 15:12:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @access private
|
|
|
|
*
|
2016-05-22 13:39:28 -04:00
|
|
|
* @param array $cron Cron info array from _get_cron_array().
|
2022-08-11 10:11:08 -04:00
|
|
|
* @return array An upgraded cron info array.
|
2008-09-04 15:12:40 -04:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
function _upgrade_cron_array( $cron ) {
|
2023-08-12 08:02:24 -04:00
|
|
|
if ( isset( $cron['version'] ) && 2 === $cron['version'] ) {
|
2006-09-13 19:54:15 -04:00
|
|
|
return $cron;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2006-09-13 19:54:15 -04:00
|
|
|
|
|
|
|
$new_cron = array();
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
foreach ( (array) $cron as $timestamp => $hooks ) {
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $hooks as $hook => $args ) {
|
2023-08-12 08:02:24 -04:00
|
|
|
$key = md5( serialize( $args['args'] ) );
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$new_cron[ $timestamp ][ $hook ][ $key ] = $args;
|
2006-09-13 19:54:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$new_cron['version'] = 2;
|
2023-08-12 08:02:24 -04:00
|
|
|
|
Options, Meta APIs: Explicitly pass `$autoload` parameter to when potentially adding new options.
It is recommended that for every option it is explicitly set whether to autoload it or not. This changeset updates relevant `update_option()` and `add_option()` calls.
Note that the `$autoload` parameter is only needed for `update_option()` if the option is potentially not present yet, i.e. the call will pass through to `add_option()`. Since WordPress core adds the majority of its options to the database during installation, only `update_option()` calls for dynamically added options need to be modified, which is what this changeset does.
As part of revisiting the autoload values for dynamically added WordPress core options, this changeset modifies some options to no longer be autoloaded, since they are only accessed in a few specific places that are not relevant for a regular request. These options are:
* `recently_activated`
* `_wp_suggested_policy_text_has_changed`
* `{upgradeLock}.lock`
* `dashboard_widget_options`
* `ftp_credentials`
* `adminhash`
* `nav_menu_options`
* `wp_force_deactivated_plugins`
* `delete_blog_hash`
* `allowedthemes`
* `{sessionId}_paused_extensions`
* `recovery_keys`
* `https_detection_errors`
* `fresh_site`
An upgrade routine is present as well that sets those options to no longer autoload for existing sites.
Props pbearne, flixos90, mukesh27, swissspidy, SergeyBiryukov, joemcgill, adamsilverstein.
Fixes #61103.
Built from https://develop.svn.wordpress.org/trunk@58975
git-svn-id: http://core.svn.wordpress.org/trunk@58371 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-09-03 14:19:14 -04:00
|
|
|
update_option( 'cron', $new_cron, true );
|
2023-08-12 08:02:24 -04:00
|
|
|
|
2006-09-13 19:54:15 -04:00
|
|
|
return $new_cron;
|
2010-12-02 11:27:16 -05:00
|
|
|
}
|