title: Wordpress custom wp-cron class doesn't firing the scheduled handler
body: <p>So, we use the Bedrock to help to code our products and I need to build a generic class to handle custom cronjobs.</p>
  
  <p>This is the base cronjob class:</p>
  
  <pre><code>&lt;?php
  namespace namespace\to\the\class;
  
  abstract class CronHelper extends AbstractHelper {
  
      /** Declare all attributes and other methods */
  
      /**
       * Setup the custom cronjob
       */
      protected function init() {
          $this-&gt;setAlias(DEFAULT_CRON_ALIAS);
          $this-&gt;setInterval(DEFAULT_CRON_INTERVAL);
          $this-&gt;setDisplay(DEFAULT_CRON_DISPLAY);
      }
  
      /**
       * Start the cronjob
       */
      public function start() {
          add_filter('cron_schedules', array($this,'customInterval'));
          add_action($this-&gt;getAlias(), array($this,'runner'));
  
          if (! wp_next_scheduled($this-&gt;getAlias())) {
              wp_schedule_event(time(), "{$this-&gt;getAlias()}_interval", $this-&gt;getAlias());
          }
      }
  
      /**
       * The custom interval builder
       *
       * @return array The custom interval setup
       */
      public function customInterval() {
          $scheduler["{$this-&gt;getAlias()}_interval"] = array('interval' =&gt; $this-&gt;getInterval(),'display' =&gt; $this-&gt;getDisplay());
          return $scheduler;
      }
  
      /**
       * The scheduler implementation function
       */
      protected abstract function runner();
  }
  </code></pre>
  
  <p>What you guys should know:</p>
  
  <ul>
  <li>AbstractHelper is a Singleton class</li>
  <li>I suppressed the getters/setters</li>
  <li>The method <code>start()</code> is fired on every page load of our site</li>
  </ul>
  
  <p>This is one implementation of the CronHelper class:</p>
  
  <pre><code>&lt;?php
  namespace namespace\to\the\class;
  
  class TestCron extends CronHelper {
  
      protected function runner() {
          // Try to print something on the nginx's error logs
          error_log('Running inside the class TestCron');
          // Create a random file just for testing
          $file = fopen('./cronjob.txt', 'w');
          fwrite($file, sprintf('Hello World [%d]', time()));
          fclose($file);
      }
  }
  </code></pre>
  
  <p>And this is how I'm instantiating everything, remember this piece of code is executed every time:</p>
  
  <pre><code>&lt;?php
  /** A lot of code above ... */
  
  // Start the Test Cronjob
  TestCron::getInstance()-&gt;setAlias('test_cron')
      -&gt;setDisplay('Test Cronjob')
      -&gt;setInterval(5) // Fire every 5 seconds
      -&gt;start();
  
  /** A lot of code below ... */
  </code></pre>
  
  <p>And every time I load the page and navigate through the site nothing happens. I was wondering what am I doing wrong?!</p>
  
  <p>Thanks for helping!</p>