I want to do a cron(executes function at specific time, like email,db backup etc) job. I searched in wordpress, i got this wp_schedule_event Here they say it will execute job when someone visits wordpress site if the specified time is passed.
I have a doubt, it is doing this only when someone visits wordpress website. Is cron job same for normal php site without any framework.
If it runs only when user visits the site, then why not can i do it in init
hook itself with a time if condition so i can achieve what wp_schedule_event
is doing without it.Like below
function test(){
if($time_condition > 20 && $time_condition < 23){
//do stuff
}
}
add_action('init','test');
As init
runs wordpress loaded, so every time user visits site this will be checked and executed.
can someone please give the difference and Which is useful for this kind of job?
I see both
wp_schedule_event
and init
are same except we need to add the condition in init
because other than that wp_schedule_event
also runs only when someone visits.