mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Cron API: Introduce wp_unschedule_hook() to clear all events attached to a hook.
This complements `wp_clear_scheduled_hook()`, which only clears events attached with specific arguments. Props arena, mordauk, jrf. Fixes #18997. git-svn-id: https://develop.svn.wordpress.org/trunk@40965 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -191,7 +191,7 @@ function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unschedule all events attached to the specified hook.
|
||||
* Unschedule all events attached to the hook with the specified arguments.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
@@ -221,6 +221,29 @@ function wp_clear_scheduled_hook( $hook, $args = array() ) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unschedule all events attached to the hook.
|
||||
*
|
||||
* Can be useful for plugins when deactivating to clean up the cron queue.
|
||||
*
|
||||
* @since 4.9.0
|
||||
*
|
||||
* @param string $hook Action hook, the execution of which will be unscheduled.
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the next timestamp for an event.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user