Automattic\WooCommerce\Internal\Utilities
ActionSchedulerUtil::has_scheduled_action
Is a matching action currently scheduled (pending or in-progress)?
Prefers as_has_scheduled_action, which only exists since Action Scheduler 3.3.0: another plugin can load an older copy early enough to win the version race against the one bundled with WooCommerce, and a bare call is then a fatal. Falls back to the much older as_next_scheduled_action, which on such a copy may report only pending actions, not in-progress ones - an accepted trade.
Reports false when Action Scheduler is not loaded at all, indistinguishable from "nothing is scheduled", and raises a doing-it-wrong notice so the condition is visible under debugging. A caller that treats a negative answer as licence to discard state should check {@see self::can_check_scheduled_actions()} first.
Метод класса: ActionSchedulerUtil{}
Хуков нет.
Возвращает
bool. True if a matching action is scheduled, false otherwise.
Использование
$result = ActionSchedulerUtil::has_scheduled_action( $hook, ?array $args, $group ): bool;
- $hook(строка) (обязательный)
- The hook of the action.
- ?array $args
- .
По умолчанию:null - $group(строка)
- The group the action is assigned to.
По умолчанию:''
Список изменений
| С версии 11.2.0 | Введена. |
Код ActionSchedulerUtil::has_scheduled_action() ActionSchedulerUtil::has scheduled action WC 11.3.0
public static function has_scheduled_action( string $hook, ?array $args = null, string $group = '' ): bool {
foreach ( array( 'as_has_scheduled_action', 'as_next_scheduled_action' ) as $function ) {
// PHPStan sees the Action Scheduler copy bundled with WooCommerce and concludes both functions
// always exist. The runtime case this guard exists for is precisely the one it cannot see.
// @phpstan-ignore-next-line function.alreadyNarrowedType -- see comment above.
if ( function_exists( $function ) ) {
// `as_next_scheduled_action` returns the timestamp of the next pending action, hence the cast.
return (bool) $function( $hook, $args, $group );
}
}
wc_doing_it_wrong(
__METHOD__,
'Action Scheduler is not loaded, so scheduled actions cannot be checked. Call this after Action Scheduler has initialized.',
'11.2.0'
);
return false;
}