Created
December 23, 2022 09:50
-
-
Save WPprodigy/370875a7c92718f2236c1516c4605e5b to your computer and use it in GitHub Desktop.
Prevent certain cron events from existing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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