WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

$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
Where you instanziate the class ($class = new MyClass())? – gmazzap 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
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. – gmazzap 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. – gmazzap Aug 18 '13 at 9:46

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

Your Answer


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.