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.

  • 1
    Where you instanziate the class ($class = new MyClass())?
    – gmazzap
    Aug 17, 2013 at 11:04
  • 1
    Yes, at the end of the class I'm instantiating it (sorry I omitted it in the excerpt).
    – flip79
    Aug 17, 2013 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.
    – gmazzap
    Aug 17, 2013 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, 2013 at 2:22
  • 1
    I copy and paste your code in my local test environment: it works perfectly.
    – gmazzap
    Aug 18, 2013 at 9:46

1 Answer 1


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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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