Search by

arraypress / wp-register-cron

arraypress

Declarative WordPress cron jobs and custom schedules, cleaned up properly on uninstall.

Package info

github.com/arraypress/wp-register-cron

pkg:composer/arraypress/wp-register-cron

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-08-25 15:44 UTC

This package is auto-updated.

Last update: 2026-09-02 16:27:12 UTC


README

Declare a plugin's scheduled jobs, and have them cleaned up properly when it is removed.

What it does

Scheduling in WordPress is two calls that must not disagree: wp_next_scheduled() before wp_schedule_event(), on the right hook, with the right arguments — and then the same arguments again at uninstall or the job is left behind forever, firing for a plugin that is no longer there.

This is the declaration instead. You say what should run and how often; the scheduling, the duplicate check and the uninstall are handled.

Features

  • Declare a job once, instead of guarding wp_schedule_event() by hand
  • Add a schedule WordPress does not have, like every five minutes
  • Pass arguments, so the same hook can run per site, feed or account
  • Unschedule everything the plugin registered, in one call at uninstall
  • Ask when a job runs next, to show in an admin screen
  • Change a schedule and have the existing event rescheduled, not duplicated

Installation

composer require arraypress/wp-register-cron

Quick start

add_action( 'init', function () {
	register_cron_job( 'myplugin_sync', [
		'schedule' => 'daily',
		'callback' => 'myplugin_run_sync',
	] );
} );

A schedule of your own, if hourly, twicedaily and daily are not enough:

register_cron_schedule(
	'every_five_minutes',
	5 * MINUTE_IN_SECONDS,
	__( 'Every five minutes', 'my-plugin' )
);

And at uninstall, the part that usually gets forgotten:

unregister_cron_jobs();

What it does not do

WordPress cron runs on traffic, not on time — a quiet site runs a "daily" job late, and a job that must be punctual needs a real system cron hitting wp-cron.php. Nothing here changes that.

Requirements

  • PHP 8.3 or later
  • WordPress 7.1 or later

License

GPL-2.0-or-later