Edit File by line
/home/barbar84/www/wp-inclu...
File: cron.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Cron API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Schedules an event to run only once.
[8] Fix | Delete
*
[9] Fix | Delete
* Schedules a hook which will be triggered by WordPress at the specified time.
[10] Fix | Delete
* The action will trigger when someone visits your WordPress site if the scheduled
[11] Fix | Delete
* time has passed.
[12] Fix | Delete
*
[13] Fix | Delete
* Note that scheduling an event to occur within 10 minutes of an existing event
[14] Fix | Delete
* with the same action hook will be ignored unless you pass unique `$args` values
[15] Fix | Delete
* for each scheduled event.
[16] Fix | Delete
*
[17] Fix | Delete
* Use wp_next_scheduled() to prevent duplicate events.
[18] Fix | Delete
*
[19] Fix | Delete
* Use wp_schedule_event() to schedule a recurring event.
[20] Fix | Delete
*
[21] Fix | Delete
* @since 2.1.0
[22] Fix | Delete
* @since 5.1.0 Return value modified to boolean indicating success or failure,
[23] Fix | Delete
* {@see 'pre_schedule_event'} filter added to short-circuit the function.
[24] Fix | Delete
* @since 5.7.0 The `$wp_error` parameter was added.
[25] Fix | Delete
*
[26] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/wp_schedule_single_event/
[27] Fix | Delete
*
[28] Fix | Delete
* @param int $timestamp Unix timestamp (UTC) for when to next run the event.
[29] Fix | Delete
* @param string $hook Action hook to execute when the event is run.
[30] Fix | Delete
* @param array $args Optional. Array containing arguments to pass to the
[31] Fix | Delete
* hook's callback function. Each value in the array
[32] Fix | Delete
* is passed to the callback as an individual parameter.
[33] Fix | Delete
* The array keys are ignored. Default empty array.
[34] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
[35] Fix | Delete
* @return bool|WP_Error True if event successfully scheduled. False or WP_Error on failure.
[36] Fix | Delete
*/
[37] Fix | Delete
function wp_schedule_single_event( $timestamp, $hook, $args = array(), $wp_error = false ) {
[38] Fix | Delete
// Make sure timestamp is a positive integer.
[39] Fix | Delete
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
[40] Fix | Delete
if ( $wp_error ) {
[41] Fix | Delete
return new WP_Error(
[42] Fix | Delete
'invalid_timestamp',
[43] Fix | Delete
__( 'Event timestamp must be a valid Unix timestamp.' )
[44] Fix | Delete
);
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
return false;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$event = (object) array(
[51] Fix | Delete
'hook' => $hook,
[52] Fix | Delete
'timestamp' => $timestamp,
[53] Fix | Delete
'schedule' => false,
[54] Fix | Delete
'args' => $args,
[55] Fix | Delete
);
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Filter to preflight or hijack scheduling an event.
[59] Fix | Delete
*
[60] Fix | Delete
* Returning a non-null value will short-circuit adding the event to the
[61] Fix | Delete
* cron array, causing the function to return the filtered value instead.
[62] Fix | Delete
*
[63] Fix | Delete
* Both single events and recurring events are passed through this filter;
[64] Fix | Delete
* single events have `$event->schedule` as false, whereas recurring events
[65] Fix | Delete
* have this set to a recurrence from wp_get_schedules(). Recurring
[66] Fix | Delete
* events also have the integer recurrence interval set as `$event->interval`.
[67] Fix | Delete
*
[68] Fix | Delete
* For plugins replacing wp-cron, it is recommended you check for an
[69] Fix | Delete
* identical event within ten minutes and apply the {@see 'schedule_event'}
[70] Fix | Delete
* filter to check if another plugin has disallowed the event before scheduling.
[71] Fix | Delete
*
[72] Fix | Delete
* Return true if the event was scheduled, false or a WP_Error if not.
[73] Fix | Delete
*
[74] Fix | Delete
* @since 5.1.0
[75] Fix | Delete
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
[76] Fix | Delete
*
[77] Fix | Delete
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue adding the event.
[78] Fix | Delete
* @param stdClass $event {
[79] Fix | Delete
* An object containing an event's data.
[80] Fix | Delete
*
[81] Fix | Delete
* @type string $hook Action hook to execute when the event is run.
[82] Fix | Delete
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
[83] Fix | Delete
* @type string|false $schedule How often the event should subsequently recur.
[84] Fix | Delete
* @type array $args Array containing each separate argument to pass to the hook's callback function.
[85] Fix | Delete
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
[86] Fix | Delete
* }
[87] Fix | Delete
* @param bool $wp_error Whether to return a WP_Error on failure.
[88] Fix | Delete
*/
[89] Fix | Delete
$pre = apply_filters( 'pre_schedule_event', null, $event, $wp_error );
[90] Fix | Delete
[91] Fix | Delete
if ( null !== $pre ) {
[92] Fix | Delete
if ( $wp_error && false === $pre ) {
[93] Fix | Delete
return new WP_Error(
[94] Fix | Delete
'pre_schedule_event_false',
[95] Fix | Delete
__( 'A plugin prevented the event from being scheduled.' )
[96] Fix | Delete
);
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if ( ! $wp_error && is_wp_error( $pre ) ) {
[100] Fix | Delete
return false;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
return $pre;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
/*
[107] Fix | Delete
* Check for a duplicated event.
[108] Fix | Delete
*
[109] Fix | Delete
* Don't schedule an event if there's already an identical event
[110] Fix | Delete
* within 10 minutes.
[111] Fix | Delete
*
[112] Fix | Delete
* When scheduling events within ten minutes of the current time,
[113] Fix | Delete
* all past identical events are considered duplicates.
[114] Fix | Delete
*
[115] Fix | Delete
* When scheduling an event with a past timestamp (ie, before the
[116] Fix | Delete
* current time) all events scheduled within the next ten minutes
[117] Fix | Delete
* are considered duplicates.
[118] Fix | Delete
*/
[119] Fix | Delete
$crons = (array) _get_cron_array();
[120] Fix | Delete
$key = md5( serialize( $event->args ) );
[121] Fix | Delete
$duplicate = false;
[122] Fix | Delete
[123] Fix | Delete
if ( $event->timestamp < time() + 10 * MINUTE_IN_SECONDS ) {
[124] Fix | Delete
$min_timestamp = 0;
[125] Fix | Delete
} else {
[126] Fix | Delete
$min_timestamp = $event->timestamp - 10 * MINUTE_IN_SECONDS;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
if ( $event->timestamp < time() ) {
[130] Fix | Delete
$max_timestamp = time() + 10 * MINUTE_IN_SECONDS;
[131] Fix | Delete
} else {
[132] Fix | Delete
$max_timestamp = $event->timestamp + 10 * MINUTE_IN_SECONDS;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
foreach ( $crons as $event_timestamp => $cron ) {
[136] Fix | Delete
if ( $event_timestamp < $min_timestamp ) {
[137] Fix | Delete
continue;
[138] Fix | Delete
}
[139] Fix | Delete
if ( $event_timestamp > $max_timestamp ) {
[140] Fix | Delete
break;
[141] Fix | Delete
}
[142] Fix | Delete
if ( isset( $cron[ $event->hook ][ $key ] ) ) {
[143] Fix | Delete
$duplicate = true;
[144] Fix | Delete
break;
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
if ( $duplicate ) {
[149] Fix | Delete
if ( $wp_error ) {
[150] Fix | Delete
return new WP_Error(
[151] Fix | Delete
'duplicate_event',
[152] Fix | Delete
__( 'A duplicate event already exists.' )
[153] Fix | Delete
);
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
return false;
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Modify an event before it is scheduled.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 3.1.0
[163] Fix | Delete
*
[164] Fix | Delete
* @param stdClass|false $event {
[165] Fix | Delete
* An object containing an event's data, or boolean false to prevent the event from being scheduled.
[166] Fix | Delete
*
[167] Fix | Delete
* @type string $hook Action hook to execute when the event is run.
[168] Fix | Delete
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
[169] Fix | Delete
* @type string|false $schedule How often the event should subsequently recur.
[170] Fix | Delete
* @type array $args Array containing each separate argument to pass to the hook's callback function.
[171] Fix | Delete
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
[172] Fix | Delete
* }
[173] Fix | Delete
*/
[174] Fix | Delete
$event = apply_filters( 'schedule_event', $event );
[175] Fix | Delete
[176] Fix | Delete
// A plugin disallowed this event.
[177] Fix | Delete
if ( ! $event ) {
[178] Fix | Delete
if ( $wp_error ) {
[179] Fix | Delete
return new WP_Error(
[180] Fix | Delete
'schedule_event_false',
[181] Fix | Delete
__( 'A plugin disallowed this event.' )
[182] Fix | Delete
);
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
return false;
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
[189] Fix | Delete
'schedule' => $event->schedule,
[190] Fix | Delete
'args' => $event->args,
[191] Fix | Delete
);
[192] Fix | Delete
uksort( $crons, 'strnatcasecmp' );
[193] Fix | Delete
[194] Fix | Delete
return _set_cron_array( $crons, $wp_error );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Schedules a recurring event.
[199] Fix | Delete
*
[200] Fix | Delete
* Schedules a hook which will be triggered by WordPress at the specified interval.
[201] Fix | Delete
* The action will trigger when someone visits your WordPress site if the scheduled
[202] Fix | Delete
* time has passed.
[203] Fix | Delete
*
[204] Fix | Delete
* Valid values for the recurrence are 'hourly', 'daily', and 'twicedaily'. These can
[205] Fix | Delete
* be extended using the {@see 'cron_schedules'} filter in wp_get_schedules().
[206] Fix | Delete
*
[207] Fix | Delete
* Note that scheduling an event to occur within 10 minutes of an existing event
[208] Fix | Delete
* with the same action hook will be ignored unless you pass unique `$args` values
[209] Fix | Delete
* for each scheduled event.
[210] Fix | Delete
*
[211] Fix | Delete
* Use wp_next_scheduled() to prevent duplicate events.
[212] Fix | Delete
*
[213] Fix | Delete
* Use wp_schedule_single_event() to schedule a non-recurring event.
[214] Fix | Delete
*
[215] Fix | Delete
* @since 2.1.0
[216] Fix | Delete
* @since 5.1.0 Return value modified to boolean indicating success or failure,
[217] Fix | Delete
* {@see 'pre_schedule_event'} filter added to short-circuit the function.
[218] Fix | Delete
* @since 5.7.0 The `$wp_error` parameter was added.
[219] Fix | Delete
*
[220] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/wp_schedule_event/
[221] Fix | Delete
*
[222] Fix | Delete
* @param int $timestamp Unix timestamp (UTC) for when to next run the event.
[223] Fix | Delete
* @param string $recurrence How often the event should subsequently recur.
[224] Fix | Delete
* See wp_get_schedules() for accepted values.
[225] Fix | Delete
* @param string $hook Action hook to execute when the event is run.
[226] Fix | Delete
* @param array $args Optional. Array containing arguments to pass to the
[227] Fix | Delete
* hook's callback function. Each value in the array
[228] Fix | Delete
* is passed to the callback as an individual parameter.
[229] Fix | Delete
* The array keys are ignored. Default empty array.
[230] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
[231] Fix | Delete
* @return bool|WP_Error True if event successfully scheduled. False or WP_Error on failure.
[232] Fix | Delete
*/
[233] Fix | Delete
function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array(), $wp_error = false ) {
[234] Fix | Delete
// Make sure timestamp is a positive integer.
[235] Fix | Delete
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
[236] Fix | Delete
if ( $wp_error ) {
[237] Fix | Delete
return new WP_Error(
[238] Fix | Delete
'invalid_timestamp',
[239] Fix | Delete
__( 'Event timestamp must be a valid Unix timestamp.' )
[240] Fix | Delete
);
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
return false;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$schedules = wp_get_schedules();
[247] Fix | Delete
[248] Fix | Delete
if ( ! isset( $schedules[ $recurrence ] ) ) {
[249] Fix | Delete
if ( $wp_error ) {
[250] Fix | Delete
return new WP_Error(
[251] Fix | Delete
'invalid_schedule',
[252] Fix | Delete
__( 'Event schedule does not exist.' )
[253] Fix | Delete
);
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
return false;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
$event = (object) array(
[260] Fix | Delete
'hook' => $hook,
[261] Fix | Delete
'timestamp' => $timestamp,
[262] Fix | Delete
'schedule' => $recurrence,
[263] Fix | Delete
'args' => $args,
[264] Fix | Delete
'interval' => $schedules[ $recurrence ]['interval'],
[265] Fix | Delete
);
[266] Fix | Delete
[267] Fix | Delete
/** This filter is documented in wp-includes/cron.php */
[268] Fix | Delete
$pre = apply_filters( 'pre_schedule_event', null, $event, $wp_error );
[269] Fix | Delete
[270] Fix | Delete
if ( null !== $pre ) {
[271] Fix | Delete
if ( $wp_error && false === $pre ) {
[272] Fix | Delete
return new WP_Error(
[273] Fix | Delete
'pre_schedule_event_false',
[274] Fix | Delete
__( 'A plugin prevented the event from being scheduled.' )
[275] Fix | Delete
);
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
if ( ! $wp_error && is_wp_error( $pre ) ) {
[279] Fix | Delete
return false;
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
return $pre;
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
/** This filter is documented in wp-includes/cron.php */
[286] Fix | Delete
$event = apply_filters( 'schedule_event', $event );
[287] Fix | Delete
[288] Fix | Delete
// A plugin disallowed this event.
[289] Fix | Delete
if ( ! $event ) {
[290] Fix | Delete
if ( $wp_error ) {
[291] Fix | Delete
return new WP_Error(
[292] Fix | Delete
'schedule_event_false',
[293] Fix | Delete
__( 'A plugin disallowed this event.' )
[294] Fix | Delete
);
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
return false;
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
$key = md5( serialize( $event->args ) );
[301] Fix | Delete
[302] Fix | Delete
$crons = _get_cron_array();
[303] Fix | Delete
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
[304] Fix | Delete
'schedule' => $event->schedule,
[305] Fix | Delete
'args' => $event->args,
[306] Fix | Delete
'interval' => $event->interval,
[307] Fix | Delete
);
[308] Fix | Delete
uksort( $crons, 'strnatcasecmp' );
[309] Fix | Delete
[310] Fix | Delete
return _set_cron_array( $crons, $wp_error );
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
/**
[314] Fix | Delete
* Reschedules a recurring event.
[315] Fix | Delete
*
[316] Fix | Delete
* Mainly for internal use, this takes the time stamp of a previously run
[317] Fix | Delete
* recurring event and reschedules it for its next run.
[318] Fix | Delete
*
[319] Fix | Delete
* To change upcoming scheduled events, use wp_schedule_event() to
[320] Fix | Delete
* change the recurrence frequency.
[321] Fix | Delete
*
[322] Fix | Delete
* @since 2.1.0
[323] Fix | Delete
* @since 5.1.0 Return value modified to boolean indicating success or failure,
[324] Fix | Delete
* {@see 'pre_reschedule_event'} filter added to short-circuit the function.
[325] Fix | Delete
* @since 5.7.0 The `$wp_error` parameter was added.
[326] Fix | Delete
*
[327] Fix | Delete
* @param int $timestamp Unix timestamp (UTC) for when the event was scheduled.
[328] Fix | Delete
* @param string $recurrence How often the event should subsequently recur.
[329] Fix | Delete
* See wp_get_schedules() for accepted values.
[330] Fix | Delete
* @param string $hook Action hook to execute when the event is run.
[331] Fix | Delete
* @param array $args Optional. Array containing arguments to pass to the
[332] Fix | Delete
* hook's callback function. Each value in the array
[333] Fix | Delete
* is passed to the callback as an individual parameter.
[334] Fix | Delete
* The array keys are ignored. Default empty array.
[335] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
[336] Fix | Delete
* @return bool|WP_Error True if event successfully rescheduled. False or WP_Error on failure.
[337] Fix | Delete
*/
[338] Fix | Delete
function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array(), $wp_error = false ) {
[339] Fix | Delete
// Make sure timestamp is a positive integer.
[340] Fix | Delete
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
[341] Fix | Delete
if ( $wp_error ) {
[342] Fix | Delete
return new WP_Error(
[343] Fix | Delete
'invalid_timestamp',
[344] Fix | Delete
__( 'Event timestamp must be a valid Unix timestamp.' )
[345] Fix | Delete
);
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
return false;
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
$schedules = wp_get_schedules();
[352] Fix | Delete
$interval = 0;
[353] Fix | Delete
[354] Fix | Delete
// First we try to get the interval from the schedule.
[355] Fix | Delete
if ( isset( $schedules[ $recurrence ] ) ) {
[356] Fix | Delete
$interval = $schedules[ $recurrence ]['interval'];
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
// Now we try to get it from the saved interval in case the schedule disappears.
[360] Fix | Delete
if ( 0 === $interval ) {
[361] Fix | Delete
$scheduled_event = wp_get_scheduled_event( $hook, $args, $timestamp );
[362] Fix | Delete
if ( $scheduled_event && isset( $scheduled_event->interval ) ) {
[363] Fix | Delete
$interval = $scheduled_event->interval;
[364] Fix | Delete
}
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
$event = (object) array(
[368] Fix | Delete
'hook' => $hook,
[369] Fix | Delete
'timestamp' => $timestamp,
[370] Fix | Delete
'schedule' => $recurrence,
[371] Fix | Delete
'args' => $args,
[372] Fix | Delete
'interval' => $interval,
[373] Fix | Delete
);
[374] Fix | Delete
[375] Fix | Delete
/**
[376] Fix | Delete
* Filter to preflight or hijack rescheduling of events.
[377] Fix | Delete
*
[378] Fix | Delete
* Returning a non-null value will short-circuit the normal rescheduling
[379] Fix | Delete
* process, causing the function to return the filtered value instead.
[380] Fix | Delete
*
[381] Fix | Delete
* For plugins replacing wp-cron, return true if the event was successfully
[382] Fix | Delete
* rescheduled, false if not.
[383] Fix | Delete
*
[384] Fix | Delete
* @since 5.1.0
[385] Fix | Delete
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
[386] Fix | Delete
*
[387] Fix | Delete
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue adding the event.
[388] Fix | Delete
* @param stdClass $event {
[389] Fix | Delete
* An object containing an event's data.
[390] Fix | Delete
*
[391] Fix | Delete
* @type string $hook Action hook to execute when the event is run.
[392] Fix | Delete
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
[393] Fix | Delete
* @type string|false $schedule How often the event should subsequently recur.
[394] Fix | Delete
* @type array $args Array containing each separate argument to pass to the hook's callback function.
[395] Fix | Delete
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
[396] Fix | Delete
* }
[397] Fix | Delete
* @param bool $wp_error Whether to return a WP_Error on failure.
[398] Fix | Delete
*/
[399] Fix | Delete
$pre = apply_filters( 'pre_reschedule_event', null, $event, $wp_error );
[400] Fix | Delete
[401] Fix | Delete
if ( null !== $pre ) {
[402] Fix | Delete
if ( $wp_error && false === $pre ) {
[403] Fix | Delete
return new WP_Error(
[404] Fix | Delete
'pre_reschedule_event_false',
[405] Fix | Delete
__( 'A plugin prevented the event from being rescheduled.' )
[406] Fix | Delete
);
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
if ( ! $wp_error && is_wp_error( $pre ) ) {
[410] Fix | Delete
return false;
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
return $pre;
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
// Now we assume something is wrong and fail to schedule.
[417] Fix | Delete
if ( 0 == $interval ) {
[418] Fix | Delete
if ( $wp_error ) {
[419] Fix | Delete
return new WP_Error(
[420] Fix | Delete
'invalid_schedule',
[421] Fix | Delete
__( 'Event schedule does not exist.' )
[422] Fix | Delete
);
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
return false;
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
$now = time();
[429] Fix | Delete
[430] Fix | Delete
if ( $timestamp >= $now ) {
[431] Fix | Delete
$timestamp = $now + $interval;
[432] Fix | Delete
} else {
[433] Fix | Delete
$timestamp = $now + ( $interval - ( ( $now - $timestamp ) % $interval ) );
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
return wp_schedule_event( $timestamp, $recurrence, $hook, $args, $wp_error );
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
/**
[440] Fix | Delete
* Unschedule a previously scheduled event.
[441] Fix | Delete
*
[442] Fix | Delete
* The $timestamp and $hook parameters are required so that the event can be
[443] Fix | Delete
* identified.
[444] Fix | Delete
*
[445] Fix | Delete
* @since 2.1.0
[446] Fix | Delete
* @since 5.1.0 Return value modified to boolean indicating success or failure,
[447] Fix | Delete
* {@see 'pre_unschedule_event'} filter added to short-circuit the function.
[448] Fix | Delete
* @since 5.7.0 The `$wp_error` parameter was added.
[449] Fix | Delete
*
[450] Fix | Delete
* @param int $timestamp Unix timestamp (UTC) of the event.
[451] Fix | Delete
* @param string $hook Action hook of the event.
[452] Fix | Delete
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
[453] Fix | Delete
* Although not passed to a callback, these arguments are used to uniquely identify the
[454] Fix | Delete
* event, so they should be the same as those used when originally scheduling the event.
[455] Fix | Delete
* Default empty array.
[456] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
[457] Fix | Delete
* @return bool|WP_Error True if event successfully unscheduled. False or WP_Error on failure.
[458] Fix | Delete
*/
[459] Fix | Delete
function wp_unschedule_event( $timestamp, $hook, $args = array(), $wp_error = false ) {
[460] Fix | Delete
// Make sure timestamp is a positive integer.
[461] Fix | Delete
if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
[462] Fix | Delete
if ( $wp_error ) {
[463] Fix | Delete
return new WP_Error(
[464] Fix | Delete
'invalid_timestamp',
[465] Fix | Delete
__( 'Event timestamp must be a valid Unix timestamp.' )
[466] Fix | Delete
);
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
return false;
[470] Fix | Delete
}
[471] Fix | Delete
[472] Fix | Delete
/**
[473] Fix | Delete
* Filter to preflight or hijack unscheduling of events.
[474] Fix | Delete
*
[475] Fix | Delete
* Returning a non-null value will short-circuit the normal unscheduling
[476] Fix | Delete
* process, causing the function to return the filtered value instead.
[477] Fix | Delete
*
[478] Fix | Delete
* For plugins replacing wp-cron, return true if the event was successfully
[479] Fix | Delete
* unscheduled, false if not.
[480] Fix | Delete
*
[481] Fix | Delete
* @since 5.1.0
[482] Fix | Delete
* @since 5.7.0 The `$wp_error` parameter was added, and a `WP_Error` object can now be returned.
[483] Fix | Delete
*
[484] Fix | Delete
* @param null|bool|WP_Error $pre Value to return instead. Default null to continue unscheduling the event.
[485] Fix | Delete
* @param int $timestamp Timestamp for when to run the event.
[486] Fix | Delete
* @param string $hook Action hook, the execution of which will be unscheduled.
[487] Fix | Delete
* @param array $args Arguments to pass to the hook's callback function.
[488] Fix | Delete
* @param bool $wp_error Whether to return a WP_Error on failure.
[489] Fix | Delete
*/
[490] Fix | Delete
$pre = apply_filters( 'pre_unschedule_event', null, $timestamp, $hook, $args, $wp_error );
[491] Fix | Delete
[492] Fix | Delete
if ( null !== $pre ) {
[493] Fix | Delete
if ( $wp_error && false === $pre ) {
[494] Fix | Delete
return new WP_Error(
[495] Fix | Delete
'pre_unschedule_event_false',
[496] Fix | Delete
__( 'A plugin prevented the event from being unscheduled.' )
[497] Fix | Delete
);
[498] Fix | Delete
}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function