Cron Class
The Cron class provides a virtual cron system for GeniXCMS, allowing you to schedule tasks (hooks) to be executed at specific times or intervals. It is designed to work similarly to WP-Cron.
⚡ How It Works
GeniXCMS Cron is a "virtual" cron. It does not require a system-level crontab to function (although you can trigger it via a real cron for better reliability). Instead, it checks for due tasks on every page load.
When a task is due, the class triggers the associated Hook with the provided arguments.
⚙️ Public API Reference
Cron::schedule(int $timestamp, string $recurrence, string $hook, array $args = [])
Schedules a recurring event.
| Parameter |
Type |
Required |
Description |
$timestamp |
int |
✅ |
Unix timestamp of the first run. |
$recurrence |
string |
✅ |
'hourly', 'twicedaily', 'daily', or 'weekly'. |
$hook |
string |
✅ |
The action hook to trigger. |
$args |
array |
❌ |
Arguments to pass to the hook. |
Cron::scheduleOnce(int $timestamp, string $hook, array $args = [])
Schedules a one-time event.
Cron::scheduleOnce(time() + 3600, 'my_one_time_action', ['id' => 123]);
Cron::unschedule(int $timestamp, string $hook, array $args = [])
Unschedules a specific event. The arguments must match exactly what was used during scheduling.
Cron::clear(string $hook)
Clears ALL scheduled events for a specific hook.
Cron::clear('my_module_sync');
Cron::getSchedules()
Returns an array of available recurrence schedules and their intervals in seconds.
📅 Default Schedules
| Key |
Interval |
Description |
hourly |
3600s |
Once every hour |
twicedaily |
43200s |
Twice per day (12h) |
daily |
86400s |
Once per day |
weekly |
604800s |
Once per week |
You can add custom schedules using the cron_schedules filter.
See Also