I'm working on an email system and they want it automated to send out emails every second thursday of the month. I've got the PHP sorted out and ready to fire a callback to send the emails, but I'm a complete newbie when it comes to cron and scheduling events.
Essentially, I have this:
echo date('M d Y', strtotime('first thursday this month'));
echo date('M d Y', strtotime('-5 hours'));
if(date('MdY',strtotime('first thursday this month')) == date('MdY',strtotime('-5 hours'))){
send_emails();
}else{
echo 'DO NOT SEND EMAILS';
}
So it checks if the current day (-5 hours for timezone) is the 'second' thursday of the month (PHP bugs out and adds a week to the date).
I'm not sure if that's what I'm going to need to do to schedule an event or what. Currently it runs when the plugin page is visited, but I'd like it to be its own process that runs regardless or not whether a page is visited.
Any help is greatly appreciated!
Thanks!