PHPackages                             doiftrue/wp-kama-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. doiftrue/wp-kama-cron

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

doiftrue/wp-kama-cron
=====================

A small class for easily adding WP Cron tasks (jobs).

v1.4.2(1mo ago)97093MITPHP

Since May 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/doiftrue/Kama_Cron)[ Packagist](https://packagist.org/packages/doiftrue/wp-kama-cron)[ Docs](https://wp-kama.com/1353)[ RSS](/packages/doiftrue-wp-kama-cron/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (4)Used By (0)

A small class for easily adding WP-Cron tasks (jobs).

This class allows you to create WordPress cron tasks quickly and simply. To avoid confusion, all task settings are specified in the first argument when creating the class instance. The class handles all the routine work required to properly register cron tasks and their intervals. The task handler (callback function) must already exist in PHP or be written separately.

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

[](#requirements)

- PHP: &gt;=7.4
- WordPress: &gt;=5.7

Examples
--------

[](#examples)

> By default, tasks are registered automatically (very fast) when you visit the admin panel, during a WP-CLI request, or during any cron request. If automatic registration is not needed, set the parameter `'auto_activate' => false` and activate tasks manually using the `activate()` method. See the example below.

> INFO: You can call `Kama_Cron` at an early stage of WordPress loading, starting from the `muplugins_loaded` hook.

> IMPORTANT: The `Kama_Cron` code must also run during cron requests, because it registers the required WP hooks that are executed in those requests. In other words, you cannot register a cron job with this code and then remove this code.

### Repeatable job

[](#repeatable-job)

#### Use the known WP interval (hourly):

[](#use-the-known-wp-interval-hourly)

```
new \Kama\WP\Kama_Cron( [
	'wpkama_core_data_check_update' => [
		'callback'      => 'wpkama_core_data_check_update',
		'interval_name' => 'hourly',
	]
] );

/**
 * Cron callback (handler) function.
 */
function wpkama_core_data_check_update(){
	// your code to do the cron job
}
```

`wpkama_core_data_check_update` is the internal name of the WP hook. You do not need to use it anywhere else in your code. Just specify a unique and understandable name (it is a good idea to use the same name as the callback function).

#### Use the unknown WP interval (10 minutes):

[](#use-the-unknown-wp-interval-10-minutes)

```
new \Kama\WP\Kama_Cron( [
	'wpkama_cron_hook' => [
		'callback'      => 'wpkama_cron_func',
		'interval_name' => '10 minutes',
	],
] );

function wpkama_cron_func(){
	// your code to do the cron job
}
```

> In this case, the class will parse the string `10 minutes` and fill in the `interval_sec` and `interval_desc` parameters automatically.

> In `interval_name`, you can specify a value in the following format: `N (min|minutes|hour|day|month)s` (for example: `10 minutes`, `2 hours`, `5 days`, `2 months`). The numeric value will be used for the `interval_sec` parameter. You can also specify an existing WP interval: `hourly`, `twicedaily`, `daily`.

### Single job

[](#single-job)

#### Single job (once):

[](#single-job-once)

```
new \Kama\WP\Kama_Cron( [
    'single_job' => [
        'callback' => 'single_job_func',
        'start_time' => 1679205600, //= strtotime('tomorrow 6am') - (int) get_option('gmt_offset'),
    ],
] );
```

#### Single job at a specific time:

[](#single-job-at-a-specific-time)

```
new \Kama\WP\Kama_Cron( [
    'single_job' => [
        'callback' => 'single_job_func',
        // start event every day at 6am by site time
        'start_time' => strtotime('tomorrow 6am') - (int) get_option('gmt_offset'),
    ],
] );
```

> IMPORTANT: For single jobs, `start_time` must be a future timestamp. If it is in the past, the event will not be scheduled.

### Pass arguments to callback

[](#pass-arguments-to-callback)

```
new \Kama\WP\Kama_Cron( [
	'my_hook' => [
		'callback'      => 'my_cron_callback',
		'interval_name' => 'hourly',
		'args'          => [ 123, 'abc' ],
	],
] );

function my_cron_callback( $post_id, $mode ){
	// do something
}
```

### Access an instance by ID

[](#access-an-instance-by-id)

```
$cron = \Kama\WP\Kama_Cron::get( 'my_cron_jobs' );
$cron->activate();
```

> NOTE: If the ID is not found, `Kama_Cron::get()` returns an empty stub instance.

### Register more than one task at once

[](#register-more-than-one-task-at-once)

Let's create 4 tasks with different intervals. Tasks are registered automatically (very fast) when you visit the admin panel, via CLI, or during a cron request.

Add the following code anywhere, for example in `functions.php` or in a plugin.

```
new \Kama\WP\Kama_Cron( [
	'id'     => 'my_cron_jobs',
	'events' => [
		// first task
		'wpkama_cron_func' => [
			'callback'      => [ MyCronCallbacks::class, 'wpkama_cron_func' ],
			'interval_name' => '10 min',
		],
		//
		'wpkama_cron_func_2' => [
			'callback'      => [ MyCronCallbacks::class, 'wpkama_cron_func_2' ],
			'interval_name' => '2 hours',
			'start_time'    => 1679205600, // start at specified UNIX time
		],
		// second task
		'wpkama_cron_func_3' => [
			'callback'      => [ MyCronCallbacks::class, 'wpkama_cron_func_3' ],
			'interval_name' => '2 hours',
			'start_time'    => strtotime('tomorrow 6am'), // run at 6 a.m. (site time will be added to this time)
		],
		//
		'wpkama_cron_func_4' => [
			'callback'      => [ MyCronCallbacks::class, 'wpkama_cron_func_4' ],
			'interval_name' => 'hourly', // this is already a known WP interval
		],
	],
] );

class MyCronCallbacks {

	public static function wpkama_cron_func(){
		$file = dirname( ABSPATH ) .'/__cron_check.txt';
		$content = current_time('mysql') ."\n";
		file_put_contents( $file, $content, FILE_APPEND );
	}

	public static function wpkama_cron_func_2(){
		// do something
	}

	public static function wpkama_cron_func_3(){
		// do something
	}

	public static function wpkama_cron_func_4(){
		// do something
	}
}
```

### Register tasks when activating the plugin

[](#register-tasks-when-activating-the-plugin)

The code below shows how to activate and deactivate tasks manually during plugin activation/deactivation.

IMPORTANT: in this case, the `auto_activate` parameter must be set to `false`: `'auto_activate' => false`.

```
// Example of activation and deactivation when `auto_activate = false`
register_activation_hook( __FILE__, function(){
	\Kama\WP\Kama_Cron::get( 'my_cron_jobs_2' )->activate();
} );

register_deactivation_hook( __FILE__, function(){
	\Kama\WP\Kama_Cron::get( 'my_cron_jobs_2' )->deactivate();
} );

new \Kama\WP\Kama_Cron( [
	'id' => 'my_cron_jobs_2',
	'auto_activate' => false, // !IMPORTANT
	'events' => [
		'wpkama_cron_func_4' => [
			'callback'      => 'wpkama_cron_func_4',
			'interval_name' => 'twicedaily',
		],
		'wpkama_cron_func_5' => [
			'callback'      => 'wpkama_cron_func_5',
			'interval_name' => '2 hours',
		],
	],
] );

function wpkama_cron_func_4(){
	// code here
}

function wpkama_cron_func_5(){
	// code here
}
```

> INFO: The `deactivate()` method will deactivate all jobs from the current pack (in the example above, there are two jobs).

\--

Plugin page: [https://wp-kama.com/1353/kama\_cron](https://wp-kama.com/1353/kama_cron)

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance99

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~713 days

Total

3

Last Release

34d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a5b59537b7030cbdd84442d082f9ae993922622afae63296809ecc528d672dc?d=identicon)[doiftrue](/maintainers/doiftrue)

---

Top Contributors

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

---

Tags

cronwordpresswordpress

### Embed Badge

![Health badge](/badges/doiftrue-wp-kama-cron/health.svg)

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

###  Alternatives

[tgmpa/tgm-plugin-activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins).

1.8k222.5k13](/packages/tgmpa-tgm-plugin-activation)[aristath/kirki

Extending the WordPress customizer

1.3k73.0k4](/packages/aristath-kirki)[afragen/git-updater

A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs.

3.3k1.6k](/packages/afragen-git-updater)[justintadlock/hybrid-carbon

God-like post featured image script.

202.5k](/packages/justintadlock-hybrid-carbon)[typisttech/wp-admin-notices

A simplified OOP implementation of the WordPress admin notices

141.2k](/packages/typisttech-wp-admin-notices)

PHPackages © 2026

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