$args Args. */ public function enqueue_async( string $hook, array $args = array() ): void { if ( $this->available() ) { as_enqueue_async_action( $hook, $args, self::GROUP ); } else { // Fallback: run on shutdown of the current request. add_action( 'shutdown', static function () use ( $hook, $args ): void { // $hook is a caller-supplied, already-prefixed action name. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound do_action_ref_array( $hook, $args ); } ); } } /** * Schedule a one-off action at a future time. * * @param int $timestamp Unix timestamp. * @param string $hook Hook name. * @param array $args Args. */ public function schedule_single( int $timestamp, string $hook, array $args = array() ): void { if ( $this->available() ) { as_schedule_single_action( $timestamp, $hook, $args, self::GROUP ); } } /** * Schedule a recurring action if not already scheduled. * * @param int $timestamp First run. * @param int $interval Seconds between runs. * @param string $hook Hook name. * @param array $args Args. */ public function schedule_recurring( int $timestamp, int $interval, string $hook, array $args = array() ): void { if ( ! $this->available() ) { return; } if ( ! as_has_scheduled_action( $hook, $args, self::GROUP ) ) { as_schedule_recurring_action( $timestamp, $interval, $hook, $args, self::GROUP ); } } /** * Cancel all scheduled instances of a hook. * * @param string $hook Hook name. */ public function cancel( string $hook ): void { if ( function_exists( 'as_unschedule_all_actions' ) ) { as_unschedule_all_actions( $hook, array(), self::GROUP ); } } }