• I’m looking over the Codex here and found this example code:

    add_action('my_hourly_event', 'do_this_hourly');
    
    function my_activation() {
    	if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
    		wp_schedule_event(time(), 'hourly', 'my_hourly_event');
    	}
    }
    add_action('wp', 'my_activation');
    
    function do_this_hourly() {
    	// do something every hour
    }

    Is there a need to call wp_clear_scheduled_hook('my_hourly_event');? And how where you hook it in?

    I’m just wondering since all examples with plugins I’ve seen need to clear the scheduled hook, but if I’m not using the functions as part of a plugin, I can’t tell if it just automatically stops or what.

    Thanks!

    EDIT: I guess this would be the function to clear the job, but again is it needed?

    add_action ( 'wp', 'my_deactivation' );
    
    function my_deactivation() {
    	wp_clear_scheduled_hook( 'my_hourly_event' );
    }
  • The topic ‘Cron Job with wp_schedule_event – Does it end?’ is closed to new replies.