Skip to content

Instantly share code, notes, and snippets.

@WPprodigy
Created December 23, 2022 09:50
Show Gist options
  • Save WPprodigy/370875a7c92718f2236c1516c4605e5b to your computer and use it in GitHub Desktop.
Save WPprodigy/370875a7c92718f2236c1516c4605e5b to your computer and use it in GitHub Desktop.
Prevent certain cron events from existing
<?php
function get_cron_events_to_ignore() {
return [
'a8c_cron_control_force_publish_missed_schedules',
'a8c_cron_control_confirm_scheduled_posts',
];
}
// If an ignorable cron event runs, let's unschedule it so it runs no more.
add_filter( 'init', function() {
foreach ( get_cron_events_to_ignore() as $event_hook ) {
add_action( $event_hook, function() use ( $event_hook ) {
wp_unschedule_hook( $event_hook );
} );
}
return $scheduled;
}, 1 );
// Prevent ignorable cron events from being registered again.
add_filter( 'pre_schedule_event', function( $scheduled, $event ) {
if ( null !== $scheduled ) {
return $scheduled;
}
if ( in_array( $event->hook, get_cron_events_to_ignore(), true ) ) {
$scheduled = false;
}
return $scheduled;
}, 1, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment