A WordPress-centric search engine for devs and theme authors



wp_get_scheduled_event ›

Since5.0.0
Deprecatedn/a
wp_get_scheduled_event ( $hook, $args = array(), $timestamp = null )
Parameters: (3)
  • (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()
  • (int|null) $timestamp Optional. Unix timestamp (UTC) of the event. If not specified, the next scheduled event is returned.
    Required: No
    Default: null
Returns:
  • (bool|object) The event object. False if the event does not exist.
Defined at:
Codex:

Retrieve a scheduled event.

Retrieve the full event object for a given event.



Source

function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) {
	if ( ! $timestamp ) {
		// Get the next scheduled event.
		$timestamp = wp_next_scheduled( $hook, $args );
	}

	/**
	 * Filter to preflight or hijack retrieving a scheduled event.
	 *
	 * Returning a non-null value will short-circuit the normal process,
	 * returning the filtered value instead.
	 *
	 * Return false if the event does not exist, otherwise an event object
	 * should be returned.
	 *
	 * @since 5.0.0
	 *
	 * @param null|bool $pre       Value to return instead. Default null to continue retrieving the event.
	 * @param string    $hook      Action hook of the event.
	 * @param array     $args      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.
	 * @param int       $timestamp Unix timestamp (UTC) of the event.
	 */
	$pre = apply_filters( 'pre_get_scheduled_event', null, $hook, $args, $timestamp );
	if ( null !== $pre ) {
		return $pre;
	}

	$crons = _get_cron_array();
	$key   = md5( serialize( $args ) );

	if ( ! $timestamp || ! isset( $crons[ $timestamp ] ) ) {
		// No such event.
		return false;
	}

	if ( ! isset( $crons[ $timestamp ][ $hook ] ) || ! isset( $crons[ $timestamp ][ $hook ][ $key ] ) ) {
		return false;
	}

	$event = (object) array(
		'hook'      => $hook,
		'timestamp' => $timestamp,
		'schedule'  => $crons[ $timestamp ][ $hook ][ $key ]['schedule'],
		'args'      => $args,
	);

	if ( isset( $crons[ $timestamp ][ $hook ][ $key ]['interval'] ) ) {
		$event->interval = $crons[ $timestamp ][ $hook ][ $key ]['interval'];
	}

	return $event;
}