WordPress.org

Make WordPress Core

Ticket #18997: 18997.patch

File 18997.patch, 905 bytes (added by mordauk, 5 years ago)
  • src/wp-includes/cron.php

     
    183183        }
    184184}
    185185
     186/**
     187* Unschedule all previously scheduled cron jobs for a hook.
     188*
     189* Can be useful for plugins when deactivating to clean up the cron queue
     190*
     191* The $hook parameter is required, so that the events can be
     192* identified.
     193*
     194* @since x.x
     195*
     196* @param string $hook Action hook, the execution of which will be unscheduled.
     197*/
     198function wp_unschedule_hook( $hook ) {
     199       
     200        $crons = _get_cron_array();
     201
     202        foreach( $crons as $timestamp => $args ) {
     203
     204                unset( $crons[$timestamp][$hook] );
     205
     206                if ( empty( $crons[$timestamp] ) ) {
     207                        unset( $crons[$timestamp] );
     208                }
     209
     210        }
     211
     212        _set_cron_array( $crons );
     213
     214}
     215
    186216/**
    187217 * Retrieve the next timestamp for a cron event.
    188218 *