Advertisement

Friday 27 February 2015

How to write a cron function in osclass.

Cron job is a inbuilt functionality in osclass script. We don't have to set our own cron function in osclass. In osclass there are THREE types of cron functions available. That are given below.

1. Hourly Cron

2. Daily Cron

3.Weekly Cron

Hourly cron will be called for each hour and will execute the function every hour. Other type of crons also will work in the same way.

How to set up a cron funtion.
Create a function inside your theme folder's function.php file.

Example:
function callCronJobHourly(){

    Do something ...

}
Add this hook after the function.
osc_add_hook('cron_hourly', 'callCronJobHourly');

This is the hook function to call this function when executing hourly cron function in osclass.This means the function callCronJobHourly() will be executed hourly once inside the script. So we can have update and delete queris for expired items inside this function , it will be checked hourly and perfom the function.

If you want to run it once per day then replace the 'cron_hourly' to 'cron_daily' in the above hook. Same way will be followed for weekly cron.