Cron events being scheduled correctly, but associated actions aren't being run
-
Hi all –
I’m trying to set up a simple recurring event using the WordPress cron functions.
By using wp_next_scheduled(‘my_scheduled_event_name’) and comparing this value to time(), I see that WordPress is correctly scheduling the event (and rescheduling the next recurrence as each scheduled time is reached).
However, the actions that I’ve attached to the event hook never run.
Here are the relevant bits of my code. First, my plugin adds an “Every 5 Minutes” schedule to the default cron schedules (this appears before any other code in my main plugin file):
add_filter( 'cron_schedules', 'filter_schedules' ); function filter_schedules( $schedules ) { $schedules['5min'] = array( 'interval' => 300, 'display' => __('Every 5 Minutes') ); return $schedules; }
Upon activation of the plugin, I schedule a recurring event:
wp_schedule_event( time() + 300, '5min', 'cron_5min' );
Again, all of this appears to be working properly.
Here’s what isn’t working:
add_action( 'cron_5min', 'my_cron_function' ); function my_cron_function() { die( 'in my_cron_function()' ); // this never happens someOtherStuff(); // if I remove the die() above, this never happens either }
Any clues? I’ve gotten the WordPress cron stuff to work before, but it’s always extremely fiddly, and I never really understand why things are (or aren’t) working.
- The topic ‘Cron events being scheduled correctly, but associated actions aren't being run’ is closed to new replies.