Download the PHP package doiftrue/wp-kama-cron without Composer
On this page you can find all versions of the php package doiftrue/wp-kama-cron. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download doiftrue/wp-kama-cron
More information about doiftrue/wp-kama-cron
Files in doiftrue/wp-kama-cron
Package wp-kama-cron
Short Description A small class for easily adding WP Cron tasks (jobs).
License MIT
Homepage https://wp-kama.com/1353/kama_cron
Informations about the package wp-kama-cron
A small class for easy adding WP Cron tasks (jobs).
This Class allow you to create WordPress Cron tasks in a quick and simple way. In order not to confuse anything, all tasks settings are specified in the first parameter when crating the class instance. The class takes care of all the routine for proper registration of Cron tasks and their intervals. The task handler (callback function) must already exist in PHP or need to be written separately!
Requirements
- PHP: >=7.1
- WordPress: >=5.0
Examples
By default, the tasks are registered automatically (it works very fast) when you visit the admin panel OR at WP_CLI request OR at any cron request. If automatic registration is not needed, specify parameter
auto_activate' => false
and activate tasks manually using methodactivate()
. See the example below.INFO: You can call
Kama_Cron
at the earliest stage of loading WP, starting from the earliestmuplugins_loaded
hook.IMPORTANT: The ``Kama_Cron'' code should also work in cron requests, because it registers the necessary WP hooks that will be executed during cron requests. In other words, you CANNOT register a cron job with this code and delete it.
Repeatable job
Use the known WP interval (hourly):
wpkama_core_data_check_update
- it's an internal name of WP hook you don't need to use it anywhere in your code - just specify unique understandable name (I think it's a good idea to name it same as callback function).
Use the unknown WP interval (10 minutes):
In this case the class will parse the string
10 minutes
and fill in theinterval_sec
andinterval_desc
parameters itself.In
interval_name
you can specify the name in the following format:N (min|minutes|hour|day|month)s
—10 minutes
,2 hours
,5 days
,2 months
, then the number will be taken to 'interval_sec' parameter. OR you can specify an existing WP interval:hourly
,twicedaily
,daily
.
Single job
Single job (once):
Repeatable Single job (once at time):
Register more than one task at once:
Let's create 4 task with different intervals. Tasks are registered automatically (it works very fast) when you visit admin panel OR from CLI OR from Cron request.
Add following code anywhere, for example in functions.php
OR in plugin.
Register tasks when activating the plugin
The code below shows how to activate and deactivate tasks customly - when activating/deactivating the plugin.
IMPORTANT: in this case the parameter auto_activate must be false: 'auto_activate' => false
!
INFO: deactivate() method will deactivate all the jobs from current pack (in the example above these are two jobs).
--
Plugin page: https://wp-kama.com/1353/kama_cron