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
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?
Neither.
Why parse code on every request when you don’t need to?