wp_schedule_single_event running twice
-
I’ve boiled down the problem to as little code as possible. I’m doing this via a plugin:
class myclass { public function __construct() { ob_start(); // Debugging cron sending two emails add_shortcode( 'rookm_test_cron', array($this, 'rookm_test_cron_shortcode')); add_action('rookm_run_cronjob',array( $this, 'rookm_action_run_cronjob' )); } public function rookm_test_cron_shortcode() { $this->_log('------- in rookm_test_cron_shortcode ----------'); $now = time(); $this->_log('$now is ' . $now); wp_schedule_single_event($now+10,'rookm_run_cronjob'); return 'ran'; } public function rookm_action_run_cronjob() { $this->_log('-----------in rookm_action_run_cronjob'); $this->_log('time() is ' . time()); wp_mail('[email protected]','test cron','body'); } }
Create a page and insert the shortcode to trigger everything.
When I click the page, the log shows:
04-May-2014 03:43:49 UTC] --- in rookm_test_cron_shortcode ---- [04-May-2014 03:43:49 UTC] $now is 1399175029
Then I load another page (this is a local dev env on my windows 7 machine, so no one else is accessing it) to trigger wp_cron….and the log shows:
[04-May-2014 03:44:02 UTC] -----------in rookm_action_run_cronjob [04-May-2014 03:44:02 UTC] time() is 1399175042 [04-May-2014 03:44:04 UTC] -----------in rookm_action_run_cronjob [04-May-2014 03:44:04 UTC] time() is 1399175044
I spit out get_option(‘cron’);
which looks like this:[1399175039]=> array(1) { ["rookm_run_cronjob"]=> array(1) { ["40cd750bba9870f18aada2478b24840a"]=> array(2) { ["schedule"]=> bool(false) ["args"]=> array(0) { } } } }
Refresh the cronlist a short bit later and its gone.
So clearly the cron is getting added. Its getting scheduled, its getting executed, twice! And getting removed.
I repeated the same thing with wp_schedule_event with the same results.
I tried a bigger offset (time()+30 and time()+300) with the same results.
I added a debug_backtrace and I can see both calls are the same, coming from wp_cron.
This is a fresh install of WP3.9 with nothing else but my plugin and 2014 theme.
I checked google and only found this:
https://wordpress.stackexchange.com/questions/124894/wp-schedule-single-event-running-twice
which has no answers.
Help!
- The topic ‘wp_schedule_single_event running twice’ is closed to new replies.