Skip to content
Advertisement

Scheduling event in wordpress starting from very next monday

I have made a plugin to send weekly newsletters. The goal is that the plugin will shoot email on every Monday.

I have few confusions here:

1 – Please have look at below code

JavaScript

So, I made my custom recurrence ‘weekly’. However I am not sure what should I provide to the $timestamp variable so, that it will start working from Monday regardless of when the plugin is activated. In my plugin I have not defined any functions for activation and deactivation as I don’t think I need them.

My second question is: The wordpress cron is different from normal cronjobs as it requires visit on website. Looking at the above code I need to know what are the possibilities that my plugin will not work. And what solution can I make? to work my informant_main_action method every Monday.

Thank You

Advertisement

Answer

assuming all else is correctly set up…you can use

JavaScript

as your timestamp. You do need to put this in a activation hook so it only runs once, you can check if the hook exists

JavaScript

Otherwise, you will a new cron job set up each time someone visits your page…..

You can supplement this with a real cron job to visit your page on a weekly basis. if you have cpanel you can use something like this (note your path will have to be updated on this). The * and numbers are when you want it to run so its min, hour, day, month, weekday

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement