I'm trying to setup a cron to run every hour, it works fine on my local vagrant box, but it doesn't seem to schedule properly on aws(elastic beanstalk). Here's the code:

register_activation_hook(__FILE__, 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');

function my_activation() {
    wp_schedule_event(time(), 'hourly', 'my_hourly_event');

function do_this_hourly() {

register_deactivation_hook(__FILE__, 'my_deactivation');

function my_deactivation() {

is something wrong with this, or is something else at play?

I have w3 total cache installed both locally and on aws, so I don't think that would be to blame, as I've heard people mention it.


  • 2
    The WordPress cron API (by default) relies on a HTTP hit - if your setup is aggressively cached, WordPress might never actually be firing (or at least not frequent enough) to trigger cron. You might want to read into how to "properly" set up cron in WordPress. Commented Sep 1, 2015 at 13:22
  • 1
    Thanks for the quick reply! I've started reading the link you provided, but I must note that the cron is never scheduled, it doesn't output when executing the following: $cron_jobs = get_option( 'cron' ); print_r($cron_jobs);, whereas locally, that same snippet shows me what I'm looking for.
    – aabreu
    Commented Sep 1, 2015 at 13:25
  • Do you have debugging enabled? Commented Sep 1, 2015 at 13:27
  • Locally yes, not on the server.
    – aabreu
    Commented Sep 1, 2015 at 13:32
  • Turn it on and activate the plugin, see if you get any errors. Commented Sep 1, 2015 at 13:41

2 Answers 2


As a general principal, you shouldn't do anything that requires an 'add_action' after the plugin activation hook. This is because WP loads and runs all plugins and THEN runs the new added one, and then does a re-direct. You have to set a DB option and hook into that. Here is the discussion from the CODEX: https://codex.wordpress.org/Function_Reference/register_activation_hook

Try doing this outside of the activation hook and see what happens.In other words, PHP runs through the whole Wordpress routine on each browser request. When you 'activate' a plugin, you actually fire two page requests to the server. This type of activity properly goes in the 2nd page request, which is the re-direct.


You may use these steps to get it to work:` 1. Setup an schedule

function my_schedule( $schedules ) {
    $schedules['hourly'] = array(
        'interval' => 60 * 60,
        'display' => __( 'One houre' )
    return $schedules;
add_filter( 'cron_schedules', 'my_schedule' );

2. Register the activation hook

register_activation_hook( __FILE__, 'my_activation' );

function my_activation() {
    $timestamp = wp_next_scheduled( 'my_hourly_event' );
    if( false == $timestamp ){
        wp_schedule_event( time(), 'hourly', 'my_hourly_event' );

3. Add action on the event

function do_this_hourly() {
    // The cron functionality and rest of your code here
add_action( 'my_hourly_event', 'do_this_hourly' );

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.