Fix unschedule command failing on WordPress 4.9#135
Merged
swissspidy merged 2 commits intotry/fix-testsfrom Mar 17, 2026
Merged
Fix unschedule command failing on WordPress 4.9#135swissspidy merged 2 commits intotry/fix-testsfrom
unschedule command failing on WordPress 4.9#135swissspidy merged 2 commits intotry/fix-testsfrom
Conversation
Merged
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix tests
Fix Mar 16, 2026
unschedule command failing on WordPress 4.9
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes wp cron event unschedule incorrectly erroring on WordPress 4.9 by avoiding empty() checks against wp_unschedule_hook() (which returns null on success in WP 4.9), and by correcting a broken error message format string.
Changes:
- Pre-counts scheduled events for a hook via
_get_cron_array()to support WP versions wherewp_unschedule_hook()doesn’t return a count. - Updates failure detection to only treat an explicit
falsereturn fromwp_unschedule_hook()as failure. - Fixes/standardizes the “No events found…” and “Failed to unschedule…” error messages.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+315
to
+318
| foreach ( $crons as $cron ) { | ||
| if ( isset( $cron[ $hook ] ) ) { | ||
| $event_count += count( $cron[ $hook ] ); | ||
| } |
| WP_CLI::error( sprintf( "Failed to unschedule events for hook '%s'.", $hook ) ); | ||
| } | ||
|
|
||
| $count = ( is_int( $unscheduled ) && $unscheduled > 0 ) ? $unscheduled : $event_count; |
swissspidy
added a commit
that referenced
this pull request
Mar 17, 2026
* Pass `$due_now` * Fix `unschedule` command failing on WordPress 4.9 (#135) * Initial plan * Fix unschedule for WP 4.9 compatibility Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * PHPStan fix --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
wp cron event unschedulealways errored on WP 4.9 becausewp_unschedule_hook()returnsnullon success in that version (since_set_cron_array()was void). Theempty()check treatednullas failure, and a format string bug (\'%1\$s— literal backslash in single-quoted string) garbled the error message further.Changes
_get_cron_array()before callingwp_unschedule_hook(), providing a reliable count across all WP versionsempty()withfalse === $unscheduled— only an explicitfalsereturn indicates failure;null(WP 4.9) and positive integers (WP 5.1+) both mean successwp_unschedule_hook()returnsnull(WP < 5.1)\'%1\$sin single-quoted string with a clean double-quoted equivalentWP version behavior:
wp_unschedule_hook()return on successnull(void_set_cron_array)📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.