Add --match-args option to wp cron event delete to target specific event instances#131
Open
Add --match-args option to wp cron event delete to target specific event instances#131
--match-args option to wp cron event delete to target specific event instances#131Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…t arguments Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add ability to delete specific cron events with args using wp cron delete
Add Mar 15, 2026
--match-args option to wp cron event delete to target specific event instances
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new --match-args flag to wp cron event delete so users can delete only cron event instances whose stored arguments match a provided value, addressing cases where multiple events share the same hook.
Changes:
- Introduces
--match-args=<args>to filter deletions by exact args match (JSON array or scalar-like input). - Adds Behat coverage for matching-by-args deletion and invalid flag combinations.
- Updates command docs/examples to include the new option.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Cron_Event_Command.php |
Adds --match-args flag handling, argument decoding, and event filtering prior to deletion. |
features/cron.feature |
Adds Behat scenarios validating correct deletion-by-args behavior and error cases. |
💡 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
+354
to
+359
| $decoded_args = json_decode( $match_args, true ); | ||
| if ( null === $decoded_args && JSON_ERROR_NONE !== json_last_error() ) { | ||
| // Not valid JSON — treat as a single string argument wrapped in an array. | ||
| $decoded_args = array( $match_args ); | ||
| } elseif ( ! is_array( $decoded_args ) ) { | ||
| $decoded_args = array( $decoded_args ); |
Comment on lines
+329
to
+340
| * [--match-args=<args>] | ||
| * : Only delete events whose arguments match the given JSON-encoded array or scalar value. Requires exactly one hook name. | ||
| * | ||
| * ## EXAMPLES | ||
| * | ||
| * # Delete all scheduled cron events for the given hook | ||
| * $ wp cron event delete cron_test | ||
| * Success: Deleted a total of 2 cron events. | ||
| * | ||
| * # Delete a specific cron event by hook and arguments | ||
| * $ wp cron event delete cron_test --match-args='[123]' | ||
| * Success: Deleted a total of 1 cron event. |
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.
When multiple cron events share the same hook but have different arguments,
wp cron event delete <hook>removes all of them. There is no way to target a single instance by its arguments.Changes
New
--match-args=<args>option onwp cron event delete'[123]','["foo","bar"]') or a plain scalar string (treated as a single-element array)--allor--due-nowBehat tests covering: JSON array match, scalar string match, and all invalid combinations (
--all,--due-now, no hook, multiple hooks)Example
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.wordpress.org/usr/bin/curl curl -s REDACTED(dns block)downloads.wordpress.org/usr/bin/curl curl -sSfL REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.