A WordPress-centric search engine for devs and theme authors



wp_next_scheduled ›

Since2.1.0
Deprecatedn/a
wp_next_scheduled ( $hook, $args = array() )
Parameters: (2)
  • (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|int) The Unix timestamp of the next time the event will occur. False if the event doesn't exist.
Defined at:
Codex:
Change Log:
  • 5.0.0

Retrieve the next timestamp for an event.



Source

function wp_next_scheduled( $hook, $args = array() ) {
	/**
	 * Filter to preflight or hijack retrieving the next scheduled event timestamp.
	 *
	 * Returning a non-null value will short-circuit the normal retrieval
	 * process, causing the function to return the filtered value instead.
	 *
	 * Pass the timestamp of the next event if it exists, false if not.
	 *
	 * @since 5.0.0
	 *
	 * @param null|bool $pre       Value to return instead. Default null to continue unscheduling the event.
	 * @param string    $hook      Action hook of the event.
	 * @param array     $args      Arguments to pass to the hook's callback function.
	 */
	$pre = apply_filters( 'pre_next_scheduled', null, $hook, $args );
	if ( null !== $pre ) {
		return $pre;
	}

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

	if ( ! empty( $crons ) ) {
		foreach ( $crons as $timestamp => $cron ) {
			if ( isset( $cron[ $hook ][ $key ] ) ) {
				$next = $timestamp;
				break;
			}
		}
	}

	/**
	 * Filter the next scheduled event timestamp.
	 *
	 * @since 5.0.0
	 *
	 * @param int|bool $next The UNIX timestamp when the scheduled event will next occur, or false if not found.
	 * @param string   $hook Action hook to execute when cron is run.
	 * @param array    $args Arguments to be passed to the callback function. Used for deduplicating events.
	 */
	return apply_filters( 'next_scheduled', $next, $hook, $args );
}