Skip to content

Commit

Permalink
Unschedule event with wrong recurrence instead of rescheduling it
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Oct 13, 2021
1 parent 422d0f2 commit bf25b0c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/BackgroundTask/RecurringBackgroundTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ final public function schedule_event( ...$args ) {

$scheduled_event = wp_get_scheduled_event( $event_name, $args );

// Unschedule any existing event which had a differing recurrence.
if ( $scheduled_event && $scheduled_event->schedule !== $recurrence ) {
wp_schedule_event( $scheduled_event->timestamp, $recurrence, $event_name, $args );
} elseif ( ! $scheduled_event ) {
wp_unschedule_event( $scheduled_event->timestamp, $event_name, $args );
$scheduled_event = null;
}

if ( ! $scheduled_event ) {
wp_schedule_event( time(), $recurrence, $event_name, $args );
}
}
Expand Down

0 comments on commit bf25b0c

Please sign in to comment.