CronScheduler
Class.
Schedules one-time WP-Cron tasks of the theme or plugin. Inject it into a service:
A task is an object of a value class with a #[CronTask] handler. Two tasks
are the same if their values are equal: WP-Cron stores the values of the task
as the argument of the event and finds, compares and unschedules events by
their arguments.
Methods
isScheduled()
Whether a task equal to the given one is scheduled.
Returns bool
Throws LogicException: If the task has no #[CronTask] handler in this theme or plugin.
schedule()
Schedules the task to run at the given time (or on the next request after it).
Returns bool: True if scheduled, false if WordPress already has the same task within 10 minutes of that time.
Throws RuntimeException: If WordPress refuses the task for another reason (e.g. a time before 1970, or a plugin).
Throws LogicException: If the task has no #[CronTask] handler in this theme or plugin.
unschedule()
Removes every scheduled task equal to the given one.
Returns int: The number of tasks removed.
Throws RuntimeException: If WordPress cannot save the cron events.
Throws LogicException: If the task has no #[CronTask] handler in this theme or plugin.