Add command to unschedule all events with a given hook #51
Conversation
Thanks for the PR @vaishaliagola27 @schlessera Could you please do a final review? Thanks |
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]; |
schlessera
Dec 17, 2019
Member
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.
Suggested change
$hook = $args[0];
list( $hook ) = $args;
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.
Suggested change
$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 ), |
schlessera
Dec 17, 2019
Member
This should use the helper provided by WP-CLI, instead of the translation functions:
Suggested change
_n( 'event', 'events', $unscheduled ),
Utils::pluralize( 'event', $unscheduled ),
This should use the helper provided by WP-CLI, instead of the translation functions:
Suggested change
_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. |
schlessera
Dec 17, 2019
Member
Suggested change
* Unchedules cron event on specific hook.
* Unschedules all cron events for a given hook.
Suggested change
* 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. |
schlessera
Dec 17, 2019
Member
Suggested change
Unchedules cron event on specific hook.
Unschedules all cron events for a given hook.
Suggested change
Unchedules cron event on specific hook. | |
Unschedules all cron events for a given hook. |
README.md
Outdated
**OPTIONS** | ||
|
||
<hook> | ||
The hook name. |
schlessera
Dec 17, 2019
Member
Suggested change
The hook name.
Name of the hook for which all events should be unscheduled.
Suggested change
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'. |
schlessera
Dec 17, 2019
Member
Suggested change
Success: Unscheduled 1 event with hook 'wp_cli_test_event_1'.
Success: Unscheduled 1 event for hook 'wp_cli_test_event_1'.
Suggested change
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'. |
schlessera
Dec 17, 2019
Member
Suggested change
Success: Unscheduled 2 events with hook 'wp_cli_test_event_2'.
Success: Unscheduled 2 events for hook 'wp_cli_test_event_2'.
Suggested change
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'. |
schlessera
Dec 17, 2019
Member
Suggested change
Error: No event found with hook 'wp_cli_test_event'.
Error: No events found for hook 'wp_cli_test_event'.
Suggested change
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. |
schlessera
Dec 17, 2019
Member
Suggested change
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.
Suggested change
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.'; |
schlessera
Dec 17, 2019
Member
Suggested change
$message = 'Event not unscheduled.';
$message = "Failed to unschedule events for hook '%1\$s'.";
Suggested change
$message = 'Event not unscheduled.'; | |
$message = "Failed to unschedule events for hook '%1\$s'."; |
@schlessera |
Thanks for the PR, @vaishaliagola27 ! |
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.
Adds unschedule command -
wp cron event unschedule <hook>
Fixes #48