Created
January 17, 2019 17:40
-
-
Save kagg-design/080d4de58331dd5428e8e9f0616f6d42 to your computer and use it in GitHub Desktop.
Clear multiple cron jobs created by Google Reviews Business plugin.
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 | |
/** | |
* Clear multiple cron jobs created by Google Reviews Business plugin. | |
*/ | |
function clear_cron_jobs() { | |
$crons = _get_cron_array(); | |
$hook = 'grp_auto_save'; | |
$args_array = array(); | |
$new_cron = array(); | |
foreach ( $crons as $timestamp => $cron ) { | |
if ( isset( $cron[ $hook ] ) ) { | |
$args = serialize( array_values($cron[ $hook ])[0]['args'] ); | |
if ( in_array( $args, $args_array, true ) ) { | |
unset( $cron[ $hook ] ); | |
} else { | |
$args_array[] = $args; | |
} | |
} | |
if ( ! empty( $cron ) ) { | |
$new_cron[ $timestamp ] = $cron; | |
} | |
} | |
_set_cron_array( $new_cron ); | |
} | |
add_action( 'shutdown', 'clear_cron_jobs' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there. Sorry for the newb question. But where do I place this code? And how do I get it to run? Thanks!