WordPress.org

Ready to get started?Download WordPress

Forums

Cron Job with wp_schedule_event - Does it end? (1 post)

  1. Adam Capriola
    Member
    Posted 2 years ago #

    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' );
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.