Which action for triggering cron “wp”or “init”?

Which one do you recommend using within a plugin and why?

add_action( 'wp', 'trigger_me' );
function trigger_me() {

    if ( !wp_next_scheduled( 'my_plugin_cron' ) ) {
        wp_schedule_event(time(), 'hourly', 'my_plugin_cron');
    }

}

OR

Read More
add_action( 'init', 'trigger_me' );
function trigger_me() {

    if ( !wp_next_scheduled( 'my_plugin_cron' ) ) {
        wp_schedule_event(time(), 'hourly', 'my_plugin_cron');
    }

}

What are the advantages/disadvantages of “wp” over “init” when registering/triggering cron function within a plugin?

Related posts

1 comment

  1. Neither.

    register_activation_hook( __FILE__, 'trigger_me' );
    
    function trigger_me() {
    
        if ( !wp_next_scheduled( 'my_plugin_cron' ) ) {
            wp_schedule_event(time(), 'hourly', 'my_plugin_cron');
        }
    
    }
    

    Why parse code on every request when you don’t need to?

Comments are closed.