as_has_scheduled_action()
Check if there is a scheduled action in the queue but more efficiently than as_next_scheduled_action().
It's recommended to use this function when you need to know whether a specific action is currently scheduled (pending or in-progress).
No Hooks.
Returns
true|false. True if a matching action is pending or in-progress, false otherwise.
Usage
as_has_scheduled_action( $hook, $args, $group );
- $hook(string) (required)
- The hook of the action.
- $args(array)
- Args that have been passed to the action. Null will matches any args.
Default: null - $group(string)
- The group the job is assigned to.
Default: ''
Changelog
| Since 3.3.0 | Introduced. |
as_has_scheduled_action() as has scheduled action code WC 10.4.3
function as_has_scheduled_action( $hook, $args = null, $group = '' ) {
if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) {
return false;
}
$query_args = array(
'hook' => $hook,
'status' => array( ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING ),
'group' => $group,
'orderby' => 'none',
);
if ( null !== $args ) {
$query_args['args'] = $args;
}
$action_id = ActionScheduler::store()->query_action( $query_args );
return null !== $action_id;
}