Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is my (stripped down) plugin, in OOP:

<?php
/*
Plugin Name: Cron Test
Plugin URI: http://www.mywebsite.com/
Description: Test
Version: 1.0
Requires at least: 3.0
*/

class CronTest {
  public function __construct() {
      if ( !wp_next_scheduled( 'dailyops' ) ) {
          wp_schedule_event( time(), 'daily', 'dailyops' );
      }
      add_action( 'dailyops', array($this, 'do_this_daily') );
  }

  function do_this_daily() {
          // do something every day
          error_log('daily');
  }
}

$cronTest = new CronTest();

Anyway, it's not working (do_this_daily() is never fired). I tried the same in a non-OOP plugin (not based on a class) and it works flawlessy. How can I make it work here, in a class?

EDIT: I replaced the initial portion of the code with a full (still minimal) plugin that can be tested.

share|improve this question
1  
Where you instanziate the class ($class = new MyClass())? –  G. M. Aug 17 '13 at 11:04
    
Yes, at the end of the class I'm instantiating it (sorry I omitted it in the excerpt). –  flip79 Aug 17 '13 at 11:09
1  
Usually I put wp_schedule_event inside an hooked function, but your code should work for me... Maybe the problem is in something not posted. –  G. M. Aug 17 '13 at 13:06
    
Thank you for your comment! I replaced the example with a full example plugin that you can directly copy and paste to test it. It doesn't work :( –  flip79 Aug 18 '13 at 2:22
    
I copy and paste your code in my local test environment: it works perfectly. –  G. M. Aug 18 '13 at 9:46
show 3 more comments

1 Answer

Finally, I discovered what was wrong: the webserver (a dedicated VPS) had a bad configuration of the hosted domain, so it was unable to "self contact" it, to call wp-cron.php .

I fixed it and now every scheduled job works, including this one :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.