Skip to content

Cronjob Helper

Mattias edited this page Aug 1, 2021 · 2 revisions

add()

The add function simplifies registering a cronjob.

add(array $args)

Parameters

  • $args (array) (Required)
    • hook (string) (Required)
    • args (array) (Required)
    • timestamp (integer) (Required)
    • recurrence (string) (Required)
    • wp_error (boolean) (Required)

Example

cronjob()->add([
    'hook'       => 'test_cron',
    'args'       => [],
    'timestamp'  => time(),
    'recurrence' => 'iroh_every_thirty_min',
    'wp_error'   => false,
]);

add_recurrence()

The add_recurrence function helps you write a new interval for any cron task.

add_recurrence(array $args)

Parameters

  • $arg (array) (Required)
    • key (string) (Required)
    • interval (integer) (Required)
    • display (string) (Required)

Example

cronjob()->add_recurrence([
    'key'      => 'iroh_every_thirty_min',
    'interval' => 1800,
    'display'  => __('Every 30 Minutes', APP_DOMAIN),
]);

registry()

The registry function returns an array of registerd tasks and schedules.

registry()

Parameters

  • None

Example

dump( cronjob()->registry() );
Clone this wiki locally