Title: andfinally's Replies | WordPress.org

---

# andfinally

  [  ](https://wordpress.org/support/users/andfinally/)

 *   [Profile](https://wordpress.org/support/users/andfinally/)
 *   [Topics Started](https://wordpress.org/support/users/andfinally/topics/)
 *   [Replies Created](https://wordpress.org/support/users/andfinally/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/andfinally/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/andfinally/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/andfinally/engagements/)
 *   [Favorites](https://wordpress.org/support/users/andfinally/favorites/)

 Search replies:

## Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)

 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [wp cron is not running my function](https://wordpress.org/support/topic/wp-cron-is-not-running-my-function/)
 *  [andfinally](https://wordpress.org/support/users/andfinally/)
 * (@andfinally)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/wp-cron-is-not-running-my-function/page/2/#post-15256937)
 * That’s a good description [@michelts](https://wordpress.org/support/users/michelts/)!
 * > So the add_action with the callback should indeed be registered in for example
   > the init hook. Or anything that is also executed / instantiated when wp-cron
   > runs.
 * I’m not sure about how calling `add_action` in the `init` hook ensures the class
   whose method you’re calling gets instantiated? But it’s an important point: an
   instance of the class must exist at the time the scheduled job runs.
 * In my case I was calling a static method, so I didn’t have that particular problem–
   but you’re right, it can be the cause of this issue in many cases.
    -  This reply was modified 4 years, 7 months ago by [andfinally](https://wordpress.org/support/users/andfinally/).
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [wp cron is not running my function](https://wordpress.org/support/topic/wp-cron-is-not-running-my-function/)
 *  [andfinally](https://wordpress.org/support/users/andfinally/)
 * (@andfinally)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/wp-cron-is-not-running-my-function/#post-15212558)
 * Hi [@lauraabraham](https://wordpress.org/support/users/lauraabraham/), I’m not
   too familiar with the Code Snippets plugin, but it looks like it should work 
   just as well as if you’d added the code to your `functions.php`. You might even
   be able to combine them in one snippet.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [wp cron is not running my function](https://wordpress.org/support/topic/wp-cron-is-not-running-my-function/)
 *  [andfinally](https://wordpress.org/support/users/andfinally/)
 * (@andfinally)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/wp-cron-is-not-running-my-function/#post-14331722)
 * In my case I was able to get it working by jiggling things round a bit. I added
   an `init` action at the root level of a file which is included by `functions.
   php`:
 *     ```
       add_action( 'init', function () {
       	if ( ! has_action( 'import_scheduled_job' ) ) {
       		add_action( 'import_scheduled_job', 'Products\do_import', 10, 2 );
       	}
       } );
       ```
   
 * And added the action handler at the root level of a file which contained my import
   class, which calls the class’s import method.
 *     ```
       namespace Products;
   
       class Product_Importer {
   
         // Other functions, including one which calls create_async_job 
         // when the user starts an import
   
         private function create_async_job( $file ) {
           if ( ! wp_next_scheduled( 'import_scheduled_job' ) ) {
             wp_schedule_single_event(
               time(),
               'import_scheduled_job',
               array(
                 'file' => $file,
                 'attachment_id' => $this->id
       	)
             );
           }
         }
   
         public static function import( $file, $attachment_id ) {
           // ...
         }
       }
   
       function do_import( $file, $attachment_id ) {
       	Product_Importer::import( $file, $attachment_id );
       }
       ```
   
 * Not very elegant, but it does the job for now. Hope this helps other people with
   the same problem. I’m still not sure why I was getting this, but judging by the
   fix, I suspect it’s something to do with the scope of classes and/or namespaces.
 * One gotcha that might catch other people: you pass an `$args` array of parameters
   when you call `wp_schedule_single_event`, but when the action handler is called,
   those params are passed individually. So if your array has two elements, specify
   2 arguments in your `add_action` call.
    -  This reply was modified 5 years, 4 months ago by [andfinally](https://wordpress.org/support/users/andfinally/).
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [wp cron is not running my function](https://wordpress.org/support/topic/wp-cron-is-not-running-my-function/)
 *  [andfinally](https://wordpress.org/support/users/andfinally/)
 * (@andfinally)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/wp-cron-is-not-running-my-function/#post-14331576)
 * I have the same issue.
    - I’ve deactivated the default cron spawning by setting `DISABLE_WP_CRON` to
      true
    - I’ve made a cron job on the host which calls `wp_cron.php?doing_wp_cron` every
      minute.
    - The event appears in the cron list using the WP Crontrol plugin, and apparently
      runs. But there is no output, either to error log or saving an option.
    - I’m able to run the job via WP-CLI, which reports that it has successfully
      run. But again, the action handler hasn’t done anything.
 * I’m able to make this work, so maybe it’s something to do with the way I’m adding
   the action handler.
 *     ```
       add_action( 'init', function () {
       	if ( ! wp_next_scheduled( 'do_single_action' ) ) {
       		wp_schedule_single_event( time(), 'do_single_action' );
       	}
   
       	add_action( 'do_single_action', 'do_this_once' );
   
       	function do_this_once() {
       		error_log( 'DO THIS ONCE' );
       	}
       } );
       ```
   
    -  This reply was modified 5 years, 4 months ago by [andfinally](https://wordpress.org/support/users/andfinally/).
    -  This reply was modified 5 years, 4 months ago by [andfinally](https://wordpress.org/support/users/andfinally/).
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Jetpack - WP Security, Backup, Speed, & Growth] Another OS X upgrade – another Jetpack conflict](https://wordpress.org/support/topic/another-os-x-upgrade-another-jetpack-conflict/)
 *  [andfinally](https://wordpress.org/support/users/andfinally/)
 * (@andfinally)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/another-os-x-upgrade-another-jetpack-conflict/#post-8542534)
 * phillipmad’s solution didn’t do the trick for me, I’m seeing this issue on a 
   Docker container on Sierra. I haven’t tried the “roll your own PHP” solution 
   yet.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [WordTube – baffled!!!!](https://wordpress.org/support/topic/wordtube-baffled/)
 *  Thread Starter [andfinally](https://wordpress.org/support/users/andfinally/)
 * (@andfinally)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/wordtube-baffled/#post-1268436)
 * Ah now I get it! You need to upload your FLV under Tools > WordTube, not under
   Media > Add new. Then [media id=1] tag works perfectly.
 * Thanks very much dconnors!
    Fred

Viewing 6 replies - 1 through 6 (of 6 total)