New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add command to unschedule all events with a given hook #51
Add command to unschedule all events with a given hook #51
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great, @vaishaliagola27 !
I have a few nitpicks regarding the language, mostly, to make it more consistent with the rest of WP-CLI.
Once we got these in shape, this is probably good for merging!
src/Cron_Event_Command.php
Outdated
*/ | ||
public function unschedule( $args, $assoc_args ) { | ||
|
||
$hook = $args[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a more recent convention, we've switched to using list()
for fetching all required positional arguments. This looks strange with only a single one, but it's always good to just stick to the convention nevertheless.
$hook = $args[0]; | |
list( $hook ) = $args; |
src/Cron_Event_Command.php
Outdated
sprintf( | ||
'Unscheduled %1$d %2$s with hook \'%3$s\'.', | ||
$unscheduled, | ||
_n( 'event', 'events', $unscheduled ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the helper provided by WP-CLI, instead of the translation functions:
_n( 'event', 'events', $unscheduled ), | |
Utils::pluralize( 'event', $unscheduled ), |
src/Cron_Event_Command.php
Outdated
@@ -269,6 +269,53 @@ public function run( $args, $assoc_args ) { | |||
WP_CLI::success( sprintf( $message, $executed ) ); | |||
} | |||
|
|||
/** | |||
* Unchedules cron event on specific hook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Unchedules cron event on specific hook. | |
* Unschedules all cron events for a given hook. |
README.md
Outdated
|
||
### wp cron event unschedule | ||
|
||
Unchedules cron event on specific hook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unchedules cron event on specific hook. | |
Unschedules all cron events for a given hook. |
README.md
Outdated
**OPTIONS** | ||
|
||
<hook> | ||
The hook name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hook name. | |
Name of the hook for which all events should be unscheduled. |
features/cron-event.feature
Outdated
And I try `wp cron event unschedule wp_cli_test_event_1` | ||
Then STDOUT should contain: | ||
""" | ||
Success: Unscheduled 1 event with hook 'wp_cli_test_event_1'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Success: Unscheduled 1 event with hook 'wp_cli_test_event_1'. | |
Success: Unscheduled 1 event for hook 'wp_cli_test_event_1'. |
features/cron-event.feature
Outdated
And I try `wp cron event unschedule wp_cli_test_event_2` | ||
Then STDOUT should contain: | ||
""" | ||
Success: Unscheduled 2 events with hook 'wp_cli_test_event_2'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Success: Unscheduled 2 events with hook 'wp_cli_test_event_2'. | |
Success: Unscheduled 2 events for hook 'wp_cli_test_event_2'. |
features/cron-event.feature
Outdated
When I try `wp cron event unschedule wp_cli_test_event` | ||
Then STDERR should be: | ||
""" | ||
Error: No event found with hook 'wp_cli_test_event'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error: No event found with hook 'wp_cli_test_event'. | |
Error: No events found for hook 'wp_cli_test_event'. |
features/cron-event.feature
Outdated
When I try `wp cron event unschedule wp_cli_test_event_1` | ||
Then STDERR should be: | ||
""" | ||
Error: The 'wp_unschedule_hook' function was only introduced in WordPress 4.9.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error: The 'wp_unschedule_hook' function was only introduced in WordPress 4.9.0. | |
Error: Unscheduling events is only supported from WordPress 4.9.0 onwards. |
src/Cron_Event_Command.php
Outdated
$unscheduled = wp_unschedule_hook( $hook ); | ||
|
||
if ( empty( $unscheduled ) ) { | ||
$message = 'Event not unscheduled.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$message = 'Event not unscheduled.'; | |
$message = "Failed to unschedule events for hook '%1\$s'."; |
@schlessera |
Thanks for the PR, @vaishaliagola27 ! |
Add command to unschedule all events with a given hook
Adds unschedule command -
wp cron event unschedule <hook>
Fixes #48