Closed StonehengeCreations closed 3 years ago
If I'm reading the source code of wp_clear_scheduled_hook()
correctly, it calls wp_unschedule_event()
which already removes cron jobs that don't have any associated hooks:
$crons = _get_cron_array();
$key = md5( serialize( $args ) );
unset( $crons[ $timestamp ][ $hook ][ $key ] );
if ( empty( $crons[ $timestamp ][ $hook ] ) ) {
unset( $crons[ $timestamp ][ $hook ] ); // <===
}
if ( empty( $crons[ $timestamp ] ) ) {
unset( $crons[ $timestamp ] ); // <===
}
wp_unschedule_hook()
has a very similar section:
unset( $crons[ $timestamp ][ $hook ] );
if ( empty( $crons[ $timestamp ] ) ) {
unset( $crons[ $timestamp ] );
}
As far as I can tell, the job should be removed if wp_clear_scheduled_hook()
is called. Maybe it didn't get called for some reason?
Obviously you are right about the practically identical code. Maybe something is going wrong at my end then... I will do some more testing why my crons keep hanging around.
May I suggest an additional line to the
removeUpdaterCron()
method in Schedular.php, please?Currently if a user deactivates the theme or plugin, the cron job will be cleared using
wp_clear_scheduled_hook()
, but as the name already suggests, that only clears the actions assigned to that cron job - the cron job itself is still there. So WordPress is still executing a cron job (do_action), without running any methods.Could you add a line in the next update to, after clearing the scheduled hook, also remove the cron job, please?
wp_unschedule_hook($this->cronHook);
Many thanks in advance, Patrick.