Skip to content

Add --match-args option to wp cron event delete to target specific event instances#131

Open
Copilot wants to merge 2 commits intomainfrom
copilot/allow-deleting-specific-cron-events
Open

Add --match-args option to wp cron event delete to target specific event instances#131
Copilot wants to merge 2 commits intomainfrom
copilot/allow-deleting-specific-cron-events

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

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 on wp cron event delete

    • Accepts a JSON-encoded array (e.g. '[123]', '["foo","bar"]') or a plain scalar string (treated as a single-element array)
    • Filters the matched hook's events to only those whose stored args strictly match the decoded value
    • Requires exactly one hook name; cannot be combined with --all or --due-now
  • Behat tests covering: JSON array match, scalar string match, and all invalid combinations (--all, --due-now, no hook, multiple hooks)

Example

# Two events, same hook, different args
wp cron event schedule process_stuff '+5 minutes' --0=123
wp cron event schedule process_stuff '+5 minutes' --0=456

# Delete only the one for user 123
wp cron event delete process_stuff --match-args='[123]'
# Success: Deleted a total of 1 cron event.

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
    • Triggering command: /usr/bin/curl curl -s REDACTED (dns block)
  • downloads.wordpress.org
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>Suggestion, allow deleting specific cron events (using args) with wp cron delete</issue_title>
<issue_description>## Feature Request

Describe your use case and the problem you are facing

I'd like to be able to delete specific cron events, including args, not just all events for a given hook name.

Let's say I have two cron events:

Hook name Args
process_stuff_for_user [123]
process_stuff_for_user [456]

Right now, if I do wp cron event delete process_stuff_for_user, it deletes all events with that hook name.

Describe the solution you'd like

Allow me to delete a specific one with e.g.

$ wp cron event delete process_stuff_for_user [123]

I suppose the args would need to be supplied as a JSON string.</issue_description>

<agent_instructions>Only scalar arguments should be supported or JSON string</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@schlessera @tylercollier The `1 task done` refers to the checked checkbox in the issue description: ![Suggestion, allow deleting specific cron events (using args) with wp cron d 2022-01-10 at 1 15 24 PM](https://user-images.githubusercontent.com/83631/148825364-7f594c61-cfa0-4b1c-90ed-810b96f2b70f.jpeg) @schlessera @tylercollier Yes, I think this could be useful. However, it might not be possible for some arguments to be provided via the CLI. For simple scalars, or even arrays through JSON, this would work, though.

💡 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.

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Cron_Event_Command.php 93.75% 1 Missing ⚠️

📢 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 --match-args option to wp cron event delete to target specific event instances Mar 15, 2026
Copilot AI requested a review from swissspidy March 15, 2026 13:37
@swissspidy swissspidy marked this pull request as ready for review March 15, 2026 19:14
@swissspidy swissspidy requested a review from a team as a code owner March 15, 2026 19:14
Copilot AI review requested due to automatic review settings March 15, 2026 19:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion, allow deleting specific cron events (using args) with wp cron delete

3 participants