wp_unschedule_hook( string $hook, bool $wp_error = false )
Unschedules all events attached to the hook.
Description
Can be useful for plugins when deactivating to clean up the cron queue.
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
-
(Required) Action hook, the execution of which will be unscheduled.
- $wp_error
-
(Optional) Whether to return a WP_Error on failure.
Default value: 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.
Source
File: wp-includes/cron.php
function wp_unschedule_hook( $hook ) {
$crons = _get_cron_array();
foreach( $crons as $timestamp => $args ) {
unset( $crons[ $timestamp ][ $hook ] );
if ( empty( $crons[ $timestamp ] ) ) {
unset( $crons[ $timestamp ] );
}
}
_set_cron_array( $crons );
}
Changelog
Version | Description |
---|---|
5.7.0 | The $wp_error parameter was added. |
5.1.0 | Return value added to indicate success or failure. |
4.9.0 | Introduced. |