PHPackages                             arraypress/wp-register-cron - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/wp-register-cron

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/wp-register-cron
===========================

A streamlined WordPress cron registration system with scheduling and job management

10PHP

Since Nov 8Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/arraypress/wp-register-cron)[ Packagist](https://packagist.org/packages/arraypress/wp-register-cron)[ RSS](/packages/arraypress-wp-register-cron/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Cron Registration Library
===================================

[](#wordpress-cron-registration-library)

A comprehensive PHP library for registering and managing WordPress cron jobs and schedules programmatically. This library provides a robust solution for creating and managing WordPress cron jobs with automatic prefixing and schedule management.

Features
--------

[](#features)

- 🚀 Simple cron job and schedule registration
- 🔄 Custom schedule intervals management
- ⏰ Single and recurring event support
- 🛠️ Simple utility functions for quick implementation
- ✅ Comprehensive error handling
- 🔍 Debug logging support
- 🔐 Plugin-specific isolation for multi-plugin environments

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- WordPress 5.0 or higher

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require arraypress/wp-register-cron
```

Basic Usage
-----------

[](#basic-usage)

Here's a simple example of registering custom schedules and cron jobs:

```
// Register custom schedule intervals
$schedules = [
    'twice_daily' => [
        'interval' => 12 * HOUR_IN_SECONDS,
        'display'  => 'Twice Daily'
    ],
    'every_6_hours' => [
        'interval' => 6 * HOUR_IN_SECONDS,
        'display'  => 'Every 6 Hours'
    ]
];

register_cron_schedules(__FILE__, $schedules, 'my_plugin');

// Register cron jobs
$jobs = [
    'sync_data' => [
        'callback' => 'sync_data_function',
        'schedule' => 'my_plugin_twice_daily',
        'args'     => ['param1', 'param2']
    ],
    'cleanup' => [
        'callback' => 'cleanup_function',
        'schedule' => false, // Single event
        'start'    => time() + HOUR_IN_SECONDS
    ]
];

register_cron_jobs(__FILE__, $jobs, 'my_plugin');

// Or register both at once
register_cron(__FILE__, $schedules, $jobs, 'my_plugin');
```

Configuration Options
---------------------

[](#configuration-options)

### Schedule Configuration

[](#schedule-configuration)

Each schedule can be configured with:

OptionTypeDescriptionintervalintTime in seconds between runsdisplaystringHuman-readable name for the schedule### Job Configuration

[](#job-configuration)

Each job can be configured with:

OptionTypeDescriptioncallbackcallableFunction to execute (required)schedulestring/boolSchedule name or false for single eventstartintTimestamp for first run (default: time())argsarrayArguments to pass to callbackUtility Functions
-----------------

[](#utility-functions)

Global helper functions for easy access:

```
// Register custom schedules
register_cron_schedules(__FILE__, $schedules, 'prefix');

// Register cron jobs
register_cron_jobs(__FILE__, $jobs, 'prefix');

// Unregister cron jobs
unregister_cron_jobs(__FILE__, $jobs, 'prefix');

// Register both schedules and jobs at once
register_cron(__FILE__, $schedules, $jobs, 'prefix');
```

Using the Class Directly
------------------------

[](#using-the-class-directly)

For more advanced usage, you can use the class directly:

```
use ArrayPress\WP\Register\Cron;

// Get instance for this plugin
$cron = Cron::instance(__FILE__);

// Optional: Set custom prefix
$cron->set_prefix('my_plugin');

// Add custom schedules
$cron->add_schedules([
    'custom_interval' => [
        'interval' => 3600,
        'display'  => 'Every Hour'
    ]
]);

// Add cron jobs
$cron->add_jobs([
    'hourly_task' => [
        'callback' => [$this, 'hourly_function'],
        'schedule' => 'custom_interval'
    ]
]);

// Install everything
$cron->install();
```

Advanced Example
----------------

[](#advanced-example)

Here's an example showing more advanced usage in a plugin class:

```
class MyPlugin {
    public function init() {
        // Register custom schedules and jobs together
        register_cron(
            __FILE__,
            [
                'every_4_hours' => [
                    'interval' => 4 * HOUR_IN_SECONDS,
                    'display'  => 'Every 4 Hours'
                ]
            ],
            [
                'data_sync' => [
                    'callback' => [$this, 'sync_data'],
                    'schedule' => 'my_plugin_every_4_hours',
                    'args'     => ['full_sync' => false]
                ],
                'daily_report' => [
                    'callback' => [$this, 'generate_report'],
                    'schedule' => 'daily',
                    'start'    => strtotime('tomorrow 1am')
                ],
                'one_time_cleanup' => [
                    'callback' => [$this, 'perform_cleanup'],
                    'schedule' => false, // Single event
                    'start'    => time() + DAY_IN_SECONDS
                ]
            ],
            'my_plugin'
        );
    }

    public function deactivate() {
        // Clean up cron jobs on deactivation
        unregister_cron_jobs(
            __FILE__,
            [
                'data_sync',
                'daily_report',
                'one_time_cleanup'
            ],
            'my_plugin'
        );
    }
}
```

Prefixing and Plugin Isolation
------------------------------

[](#prefixing-and-plugin-isolation)

The library uses two levels of isolation:

1. Plugin File (`__FILE__`): Ensures each plugin maintains its own isolated instance of the cron manager
2. Prefix (optional): Creates unique identifiers for cron hooks and options

If no prefix is provided, the plugin's basename will be used as the prefix automatically.

Debug Mode
----------

[](#debug-mode)

Debug logging is enabled when WP\_DEBUG is true:

```
// Logs will include:
// - Schedule registration
// - Job scheduling
// - Invalid configurations
// - Job removals
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License
-------

[](#license)

This project is licensed under the GPL2+ License. See the LICENSE file for details.

Support
-------

[](#support)

For support, please use the [issue tracker](https://github.com/arraypress/wp-register-cron/issues).

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance47

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (4 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-register-cron/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-register-cron/health.svg)](https://phpackages.com/packages/arraypress-wp-register-cron)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
