-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Per this issue on the Cavalcade repo when db latency is a factor the common pattern of checking for and scheduling cron jobs is often done on init. WP core does this as well many 3rd party plugins etc...
In theory we could avoid this altogether using the preflight filter to limit these checks to the admin only, provided they are added during the init hook:
add_filter( 'pre_get_scheduled_event', function ( $pre ) {
if ( ! doing_action( 'init' ) || is_admin() ) {
return $pre;
}
return true;
}, 1 );Events will still be scheduled but on admin requests only.
This would cause issues if plugins are adding events on the frontend using the init hook based on user interactions and $_GET or $_POST parameters, although that would be far more likely dealt with not on the init hook.
This approach seems safe to me, especially if we also check that $_POST is empty. Would be great to get some additional input and feedback though.