as_next_scheduled_action()
Check if there is an existing action in the queue with a given hook, args and group combination.
An action in the queue could be pending, in-progress or async. If the is pending for a time in future, its scheduled date will be returned as a timestamp. If it is currently being run, or an async action sitting in the queue waiting to be processed, in which case boolean true will be returned. Or there may be no async, in-progress or pending action for this hook, in which case, boolean false will be the return value.
No Hooks.
Returns
Int|true|false. The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action.
Usage
as_next_scheduled_action( $hook, $args, $group );
- $hook(string) (required)
- Name of the hook to search for.
- $args(array)
- Arguments of the action to be searched.
Default: null - $group(string)
- Group of the action to be searched.
Default: ''
as_next_scheduled_action() as next scheduled action code WC 10.3.6
function as_next_scheduled_action( $hook, $args = null, $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return false;
}
$params = array(
'hook' => $hook,
'orderby' => 'date',
'order' => 'ASC',
'group' => $group,
);
if ( is_array( $args ) ) {
$params['args'] = $args;
}
$params['status'] = ActionScheduler_Store::STATUS_RUNNING;
$action_id = ActionScheduler::store()->query_action( $params );
if ( $action_id ) {
return true;
}
$params['status'] = ActionScheduler_Store::STATUS_PENDING;
$action_id = ActionScheduler::store()->query_action( $params );
if ( null === $action_id ) {
return false;
}
$action = ActionScheduler::store()->fetch_action( $action_id );
$scheduled_date = $action->get_schedule()->get_date();
if ( $scheduled_date ) {
return (int) $scheduled_date->format( 'U' );
} elseif ( null === $scheduled_date ) { // pending async action with NullSchedule.
return true;
}
return false;
}