Support » Plugins » Hacks » wp_schedule_single_event running twice

  • Resolved gmisura


    I’ve boiled down the problem to as little code as possible. I’m doing this via a plugin:

    class myclass {
      public function __construct() {
        // 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);
        return 'ran';
      public function rookm_action_run_cronjob() {
        $this->_log('-----------in rookm_action_run_cronjob');
        $this->_log('time() is ' . time());
        wp_mail('','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:

      array(1) {
        array(1) {
          array(2) {
            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:

    which has no answers.


Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_schedule_single_event running twice’ is closed to new replies.