n the hook triggers. * * @return int The action ID. */ public function enqueue_async_action( string $hook, $args = [] ): int { $this->async_runner->attach_shutdown_hook(); return $this->schedule_immediate( $hook, $args ); } /** * Check if there is an existing action in the queue with a given hook and args combination. * * An action in the queue could be pending, in-progress or async. If the action is pending for a time in * future, currently being run, or an async action sitting in the queue waiting to be processed, 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. * * @param string $hook * @param array|null $args * * @return bool True if there is a pending scheduled, async or in-progress action in the queue or false if there is no matching action. */ public function has_scheduled_action( string $hook, $args = [] ): bool { return ( false !== as_next_scheduled_action( $hook, $args, $this->get_slug() ) ); } /** * Search for scheduled actions. * * @param array|null $args See as_get_scheduled_actions() for possible arguments. * @param string $return_format OBJECT, ARRAY_A, or ids. * * @return array */ public function search( $args = [], $return_format = OBJECT ): array { $args['group'] = $this->get_slug(); return as_get_scheduled_actions( $args, $return_format ); } /** * Cancel the next scheduled instance of an action with a matching hook (and optionally matching args). * * Any recurring actions with a matching hook should also be cancelled, not just the next scheduled action. * * @param string $hook The hook that the job will trigger. * @param array|null $args Args that would have been passed to the job. * * @return int The scheduled action ID if a scheduled action was found. * * @throws ActionSchedulerException If no matching action found. */ public function cancel( string $hook, $args = [] ) { $action_id = as_unschedule_action( $hook, $args, $this->get_slug() ); if ( null === $action_id ) { throw ActionSchedulerException::action_not_found( $hook ); } return $action_id; } /** * Retrieve an action. * * @param int $action_id Action ID. * * @return ActionScheduler_Action * * @since 1.7.0 */ public function fetch_action( int $action_id ): ActionScheduler_Action { return ActionSchedulerCore::store()->fetch_action( $action_id ); } } n the hook triggers. * * @return int The action ID. */ public function enqueue_async_action( string $hook, $args = [] ): int { $this->async_runner->attach_shutdown_hook(); return $this->schedule_immediate( $hook, $args ); } /** * Check if there is an existing action in the queue with a given hook and args combination. * * An action in the queue could be pending, in-progress or async. If the action is pending for a time in * future, currently being run, or an async action sitting in the queue waiting to be processed, 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. * * @param string $hook * @param array|null $args * * @return bool True if there is a pending scheduled, async or in-progress action in the queue or false if there is no matching action. */ public function has_scheduled_action( string $hook, $args = [] ): bool { return ( false !== as_next_scheduled_action( $hook, $args, $this->get_slug() ) ); } /** * Search for scheduled actions. * * @param array|null $args See as_get_scheduled_actions() for possible arguments. * @param string $return_format OBJECT, ARRAY_A, or ids. * * @return array */ public function search( $args = [], $return_format = OBJECT ): array { $args['group'] = $this->get_slug(); return as_get_scheduled_actions( $args, $return_format ); } /** * Cancel the next scheduled instance of an action with a matching hook (and optionally matching args). * * Any recurring actions with a matching hook should also be cancelled, not just the next scheduled action. * * @param string $hook The hook that the job will trigger. * @param array|null $args Args that would have been passed to the job. * * @return int The scheduled action ID if a scheduled action was found. * * @throws ActionSchedulerException If no matching action found. */ public function cancel( string $hook, $args = [] ) { $action_id = as_unschedule_action( $hook, $args, $this->get_slug() ); if ( null === $action_id ) { throw ActionSchedulerException::action_not_found( $hook ); } return $action_id; } /** * Retrieve an action. * * @param int $action_id Action ID. * * @return ActionScheduler_Action * * @since 1.7.0 */ public function fetch_action( int $action_id ): ActionScheduler_Action { return ActionSchedulerCore::store()->fetch_action( $action_id ); } }