A WordPress-centric search engine for devs and theme authors



wp_unschedule_event ›

Since2.1.0
Deprecatedn/a
wp_unschedule_event ( $timestamp, $hook, $args = array() )
Parameters: (3)
  • (int) $timestamp Unix timestamp (UTC) of the event.
    Required: Yes
  • (string) $hook Action hook of the event.
    Required: Yes
  • (array) $args Optional. Array containing each separate argument to pass to the hook's callback function. Although not passed to a callback, these arguments are used to uniquely identify the event, so they should be the same as those used when originally scheduling the event.
    Required: No
    Default: array()
Returns:
  • (false|void) False if the event did not get unscheduled.
Defined at:
Codex:

Unschedule a previously scheduled event.

The $timestamp and $hook parameters are required so that the event can be identified.



Source

function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
	// Make sure timestamp is a positive integer
	if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
		return false;
	}

	$crons = _get_cron_array();
	$key   = md5( serialize( $args ) );
	unset( $crons[ $timestamp ][ $hook ][ $key ] );
	if ( empty( $crons[ $timestamp ][ $hook ] ) ) {
		unset( $crons[ $timestamp ][ $hook ] );
	}
	if ( empty( $crons[ $timestamp ] ) ) {
		unset( $crons[ $timestamp ] );
	}
	_set_cron_array( $crons );
}