Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_unschedule_event ›

Seit2.1.0
Veraltetn/v
wp_unschedule_event ( $timestamp, $hook, $args = array() )
Parameter: (3)
  • (int) $timestamp Unix timestamp (UTC) of the event.
    Erforderlich: Ja
  • (string) $hook Action hook of the event.
    Erforderlich: Ja
  • (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.
    Erforderlich: Nein
    Standard: array()
Gibt zurück:
  • (bool) True if event successfully unscheduled. False for failure.
Definiert in:
Codex:
Changelog:
  • 5.0.0

Unschedule a previously scheduled event.

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



Quellcode

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

	/**
	 * Filter to preflight or hijack unscheduling of events.
	 *
	 * Returning a non-null value will short-circuit the normal unscheduling
	 * process, causing the function to return the filtered value instead.
	 *
	 * For plugins replacing wp-cron, return true if the event was successfully
	 * unscheduled, false if not.
	 *
	 * @since 5.0.0
	 *
	 * @param null|bool $pre       Value to return instead. Default null to continue unscheduling the event.
	 * @param int       $timestamp Timestamp for when to run the event.
	 * @param string    $hook      Action hook, the execution of which will be unscheduled.
	 * @param array     $args      Arguments to pass to the hook's callback function.
	 */
	$pre = apply_filters( 'pre_unschedule_event', null, $timestamp, $hook, $args );
	if ( null !== $pre ) {
		return $pre;
	}

	$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 ] );
	}
	return _set_cron_array( $crons );
}