This documentation describes unreleased changes on the main branch.

#[CronEvent]

Attribute on methods.

use Saij\WpAppFramework\Cron\CronEvent;

Runs a public method of a service as a recurring WP-Cron event.

The method returns void; its parameters are services, because WP-Cron passes no arguments to recurring events. The event is scheduled on the first request, rescheduled when the interval, at or weekday changes and unscheduled when the method loses the attribute. Its hook is wp_app_framework/cron/{slug}/{name}.

$interval is a CronInterval or a number of seconds (at least 60). Write the number itself (15 * 60): attribute arguments are evaluated in the build, where WordPress constants such as MINUTE_IN_SECONDS do not exist.

$at (HH:MM, in the time zone of the site) fixes the start time of daily, twice daily and weekly events; weekly events with $at also need $weekday.

Arguments

#[CronEvent(string $name, CronInterval|int $interval, ?string $at = null, ?Weekday $weekday = null)]
ParameterTypeDefaultDescription
namestringrequiredLowercase letters, digits and hyphens, starting with a letter; unique among the events of the theme or plugin.
intervalCronInterval|intrequiredA WordPress interval or seconds, at least 60.
atstring|nullnullStart time HH:MM in the time zone of the site.
weekdayWeekday|nullnullDay of weekly events with $at.