Retrieves the timestamp of the next scheduled event for the given hook.
Parameters
$hook
stringrequired- Action hook of the event.
$args
arrayoptional- 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.
Default:
array()
Source
function wp_next_scheduled( $hook, $args = array() ) {
$next_event = wp_get_scheduled_event( $hook, $args );
if ( ! $next_event ) {
return false;
}
/**
* Filters the timestamp of the next scheduled event for the given hook.
*
* @since 6.8.0
*
* @param int $timestamp Unix timestamp (UTC) for when to next run the event.
* @param object $next_event {
* An object containing an event's data.
*
* @type string $hook Action hook of the event.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string $schedule How often the event should subsequently recur.
* @type array $args Array containing each separate argument to pass to the hook
* callback function.
* @type int $interval Optional. The interval time in seconds for the schedule. Only
* present for recurring events.
* }
* @param array $args Array containing each separate argument to pass to the hook
* callback function.
*/
return apply_filters( 'wp_next_scheduled', $next_event->timestamp, $next_event, $hook, $args );
}
Hooks
- apply_filters( ‘wp_next_scheduled’,
int $timestamp ,object $next_event ,array $args ) Filters the timestamp of the next scheduled event for the given hook.
Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |
Note the $args parameter! Not specifying the $args parameter in wp_next_scheduled but having $args for wp_schedule_event will cause many events to be scheduled (instead of just one).
Bad Example:
Good Example:
Be careful when using arguments! WordPress doesn’t compare them 1:1 so you have to pay attention what type these are.
It’s because WP generates a hash out of them:
md5( serialize( $args ) )
So when you have:
And use a string because ie. the value was taken from the meta:
It will return false.