InstaCRON is a WordPress plugin that lets you quickly setup tasks (or "jobs") that execute when you want them to by visiting a special URL.
You register your jobs anywhere you'd like in your code (as long as it's on or after the plugins_loaded hook). See examples below.
Please note: You will need a real CRON scheduler to use this plugin. We're planning on providing "fake" CRON using TLC Transients in the future.
Creating a CRON job can be done in just a few lines of code:
InstaCRON::add_job('my_custom_job', function() {
/* Your CRON code here */
});
InstaCRON::add_job('my_custom_job_with_parameter', function($params)
{
echo "Hello, " . $params['name']; //Please don't actually echo stuff in your CRON jobs! :-)
}, array('name' => 'Timmy'));
To actually run the CRON you need to schedule a job that grabs the special InstaCRON URL as often as you'd like, which then immediately runs the code you provided. Use the custom_cron GET variable and set it to the $slug you provided in add_job()
http://site.com/?custom_cron=my_custom_job
curl http://site.com/?custom_cron=my_custom_job >/dev/null 2>&1
0 * * * * curl http://site.com/?custom_cron=my_custom_job >/dev/null 2>&1
(Scheduled once per hour via crontab)
There is an option to run all available cron jobs, simply pass the parameter "all" via the custom_cron GET variable, like this:
http://site.com/?custom_cron=all
Naturally, you can't use "all" as your $slug for jobs. We don't actually check for it tho', so we're gonna have to use the honor system on this one!
If you won't know for sure whether InstaCRON is available, don't forget to check before using the add_job function:
if(class_exists('InstaCRON'))
{
InstaCRON::add_job('my_custom_job', function()
{
/* Your CRON code here */
});
}
No problem! Use the instacron_parameter filter.
add_filter('instacron_parameter', function($param)
{
return 'my_param';
});
New URL:
http://site.com/?my_param=my_custom_job
Anything 5.3 and over should work!