Use wp_schedule_single_event() for Run Now to fix Cavalcade compatibility#276
Open
Gilmoursa wants to merge 1 commit into
Open
Use wp_schedule_single_event() for Run Now to fix Cavalcade compatibility#276Gilmoursa wants to merge 1 commit into
Gilmoursa wants to merge 1 commit into
Conversation
1b23851 to
4cb41a1
Compare
…lity force_schedule_single_event() bypassed wp_schedule_single_event() to avoid the duplicate-event check, but this meant third-party cron runners like Cavalcade never saw the pre_schedule_event filter fire. The result was a false "Failed to schedule" error even though the event was created in Cavalcade's database. Since the plugin requires WP 6.4+, the modern duplicate check uses abs($existing - $new_timestamp) <= 10 minutes. Scheduling at timestamp 1 (epoch) means this distance is always enormous for any real event, so the duplicate check never triggers. wp_schedule_single_event() is now safe to use directly, which allows Cavalcade and other cron runners to intercept the scheduling via their hooks. The force_schedule_single_event() function is removed as it's no longer used and was always an internal implementation detail. Fixes johnbillion#56
4cb41a1 to
c4fe938
Compare
Owner
|
Excellent spot, thanks. I rebased this PR to remove the commit with the capability changes. I'll do some testing. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #56.
Clicking "Run Now" on an event produced a false "Failed to schedule the cron event" error for sites running Cavalcade (and likely other alternative cron runners). The event was actually created in Cavalcade's database, but WP Crontrol reported failure.
Root cause
force_schedule_single_event()bypassedwp_schedule_single_event()and called_set_cron_array()directly. This meant Cavalcade'spre_schedule_eventfilter hook never fired. Cavalcade's handling of the raw_set_cron_array()call returned a falsy value, triggering thefalse === $resultcheck that produced the error.Why force_schedule_single_event() existed
It was introduced to bypass WordPress's duplicate-event check, which (in older WP versions) would reject scheduling a new event when an identical one was already pending within 10 minutes of now.
Why it's no longer needed
Since WP 6.4 (this plugin's minimum), the duplicate check compares timestamps:
"Run Now" schedules at timestamp
1(Unix epoch, 1970). The distance between epoch and any real future cron event is always orders of magnitude larger than 10 minutes, so the duplicate check never triggers.Fix
Replace
force_schedule_single_event()withwp_schedule_single_event( 1, $hookname, $event->args, true ). This:pre_schedule_eventso Cavalcade (and others) can intercept correctlyWP_Erroron failure (WP 5.7+$wp_error = trueparam)duplicate_eventerror code defensively (treat as already-queued, not a failure)force_schedule_single_event()is removed entirely as it's no longer used and was an internal implementation detail.Test plan