I recently had the struggle of deleting cron jobs from a site within a Multisite network. None of the delete cron functions seemed to work for me, so I wrote a function to brute-force it.
I’m all ears for a better way
//Removes a cron based on a hook name
function delete_cron_hooks( $hooks = array(), $blog_id = 0 ) {
if ( is_multisite() && $blog_id != 0 ) {
switch_to_blog( $blog_id );
}
$crons = get_option( 'cron' );
if ( !$crons ) return false;
foreach ( $crons as $timestamp => $cron ) {
foreach ( $hooks as $hook ) {
if ( isset( $cron[ $hook ] ) ) {
unset( $crons[ $timestamp ] );
}
}
}
update_option( 'cron', $crons );
} //end delete_cron
good demo