Description
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 PHP documentation. Use the ===
operator for testing the return value of this function.
Parameters
- $hook
-
(string) (Required) Action hook, the execution of which will be unscheduled.
- $args
-
(array) (Optional) Arguments that were to be passed to the hook's callback function.
Default value: array()
Return
(int|false) On success an integer indicating number of events unscheduled (0 indicates no events were registered with the hook and arguments combination), false if unscheduling one or more events fail.
If you created a scheduled job using a hook and arguments, you cannot delete it by supplying only the hook. Similarly, if you created a set of scheduled jobs that share a hook but have different arguments, you cannot delete them using only the hook name, you have to delete them all individually using the hook name and arguments.
Source
File: wp-includes/cron.php
function wp_clear_scheduled_hook( $hook, $args = array() ) {
if ( ! is_array( $args ) ) {
_deprecated_argument( __FUNCTION__, '3.0.0', __( 'This argument has changed to an array to match the behavior of the other cron functions.' ) );
$args = array_slice( func_get_args(), 1 );
}
$pre = apply_filters( 'pre_clear_scheduled_hook', null, $hook, $args );
if ( null !== $pre ) {
return $pre;
}
$crons = _get_cron_array();
if ( empty( $crons ) ) {
return 0;
}
$results = array();
$key = md5( serialize( $args ) );
foreach ( $crons as $timestamp => $cron ) {
if ( isset( $cron[ $hook ][ $key ] ) ) {
$results[] = wp_unschedule_event( $timestamp, $hook, $args );
}
}
if ( in_array( false, $results, true ) ) {
return false;
}
return count( $results );
}