• Resolved CoBu1

    (@cobu1)


    So I know how to schedule a CRON event:

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

    And usually you would run this on plugin activation to avoid scheduling an event every time WordPress is initialized:

    
    register_activation_hook(__FILE__, 'setup_cron');
    

    But how would I setup this same type of CRON in a Must-Use plugin, which of course never fires an activation hook? How can I setup an hourly CRON once without a new event being scheduled every time my site is loaded?

    Thank you!

    • This topic was modified 8 years, 1 month ago by CoBu1.
Viewing 1 replies (of 1 total)
  • Thread Starter CoBu1

    (@cobu1)

    Nevermind, it seems like it works fine as long as I use wp_next_scheduled() to check if the hook exists first.

    The codex is what confused me because it makes it seem like you’ll schedule a new event every time the page is loaded if you don’t hook it to the plugin activation.

Viewing 1 replies (of 1 total)
  • The topic ‘How to setup an hourly CRON with a Must-Use Plugin?’ is closed to new replies.