3

This is a practically copy/pasted version of the hourly wp_schedule_event example taken from the .org site. Its not moving...and I know I have visitors to "trigger" it. Its kind of a pain to wait an hour to see if it goes or not.

Can someone tell me where I'm going wrong? The only thing I can think is that I'm running it in a theme, and maybe it only works in a plugin setting? I'm lost.

//set up hourly fetching of symbiocards
register_activation_hook( __FILE__, 'symbiostock_chron_activation' );
add_action( 'symbiostock_twicedaily_symbiocard_update', 'update_symbiocards' );

function symbiocards_activation() {
    if ( !wp_next_scheduled( 'symbiocards_hourly_event' ) ) {
        wp_schedule_event( time(), 'hourly', 'symbiocards_hourly_event');
    }
}
add_action('wp', 'symbiocards_activation');

function update_symbiocards() {

    $update = new network_manager();
    $sites  = $update->get_connected_networks();
    foreach ( $sites as $site ) {
        $update->fetch_symbiocard( $site[ 'address' ] );
    } //$sites as $site

    symbiostock_save_network_info();

    update_option('symbiocards_last_update', current_time( 'mysql' ));

    wp_mail( get_bloginfo( 'admin_email' ), '[symbiostock_network_update] Network Symbiocards Updated - ' . current_time( 'mysql' ), 'Network Symbiocards Updated - ' . current_time( 'mysql' ) );
}
  • Do you have any traffic on your site? wp_schedule_event() only fires via psuedo cron or when you have actual hits. Just a sanity check... – Brian Fegter May 20 '13 at 8:54
  • Yes - always traffic...wordpress is being called all the time. – user1915665 May 20 '13 at 9:04
10

In your code example you have:

wp_schedule_event( time(), 'hourly', 'symbiocards_hourly_event');

but there is no symbiocards_hourly_event hook defined.

If you are using it in the functions.php file in your current theme directory, then please try this snippet instead:

add_action( 'wp', 'symbiocards_activation' );
add_action( 'symbiocards_hourly_event', 'update_symbiocards' );

function symbiocards_activation() {
    if ( !wp_next_scheduled( 'symbiocards_hourly_event' ) ) {
        wp_schedule_event( time(), 'hourly', 'symbiocards_hourly_event' );
    }
}

function update_symbiocards() {
    wp_mail( get_bloginfo( 'admin_email' ), '[symbiostock_network_update] Network Symbiocards Updated - ' . current_time( 'mysql' ), 'Network Symbiocards Updated - ' . current_time( 'mysql' ) );
}

where you should convince yourself that the wp_mail() part is working and is using the correct email address.

There are many good cron manager plugins out there that you can use to debug your problem. Here is for example a view from the FFF Cron Manager:

cron view

  • This worked great! Can't thank you enough. I wish I could upvote you more than once! – user1915665 May 20 '13 at 20:38
  • great to hear it worked for you, good luck with your project. – birgire May 20 '13 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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