From a914312390f42755f35e6e7c48e3be8763af26b3 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Thu, 8 Jun 2023 11:41:53 +0300 Subject: [PATCH 1/9] Reapply earlier changes --- README.md | 12 ++- features/cron.feature | 101 ++++++++++++++++++++- src/Cron_Event_Command.php | 180 +++++++++++++++++++++---------------- 3 files changed, 207 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index 702c9b7c..89424bc9 100644 --- a/README.md +++ b/README.md @@ -86,13 +86,19 @@ wp cron event Deletes all scheduled cron events for the given hook. ~~~ -wp cron event delete +wp cron event delete [...] [--due-now] [--all] ~~~ **OPTIONS** - - The hook name. + [...] + One or more hooks to delete. + + [--due-now] + Delete all hooks due right now. + + [--all] + Delete all hooks. **EXAMPLES** diff --git a/features/cron.feature b/features/cron.feature index 86981138..626e9ad8 100644 --- a/features/cron.feature +++ b/features/cron.feature @@ -37,7 +37,8 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete wp_cli_test_event_1` Then STDOUT should contain: """ - Success: Deleted the cron event 'wp_cli_test_event_1' + Deleted the cron event 'wp_cli_test_event_1' + Success: Deleted a total of 1 cron event. """ When I run `wp cron event list` @@ -123,7 +124,9 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete wp_cli_test_event_5` Then STDOUT should be: """ - Success: Deleted 2 instances of the cron event 'wp_cli_test_event_5'. + Deleted the cron event 'wp_cli_test_event_5' + Deleted the cron event 'wp_cli_test_event_5' + Success: Deleted a total of 2 cron events. """ When I run `wp cron event list` @@ -135,7 +138,7 @@ Feature: Manage WP-Cron events and schedules When I try `wp cron event delete wp_cli_test_event_5` Then STDERR should be: """ - Error: Invalid cron event 'wp_cli_test_event_5'. + Error: Invalid cron event 'wp_cli_test_event_5' """ Scenario: Scheduling and then running a re-occurring event @@ -174,7 +177,8 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete wp_cli_test_event_2` Then STDOUT should contain: """ - Success: Deleted the cron event 'wp_cli_test_event_2' + Deleted the cron event 'wp_cli_test_event_2' + Success: Deleted a total of 1 cron event. """ When I run `wp cron event list` @@ -398,3 +402,92 @@ Feature: Manage WP-Cron events and schedules """ Warning: Ignoring incorrectly registered cron event "wp_batch_split_terms". """ + + Scenario: Delete multiple cron events + When I run `wp cron event schedule wp_cli_test_event_1 '+1 hour 5 minutes' hourly` + Then STDOUT should not be empty + + When I run `wp cron event schedule wp_cli_test_event_2 '+1 hour 5 minutes' hourly` + Then STDOUT should not be empty + + When I try `wp cron event delete` + Then STDERR should be: + """ + Error: Please specify one or more cron events, or use --due-now/--all. + """ + + # WP throws a notice here for older versions of core. + When I try `wp cron event delete --all` + Then STDOUT should contain: + """ + Deleted the cron event 'wp_cli_test_event_1' + """ + And STDOUT should contain: + """ + Deleted the cron event 'wp_cli_test_event_2' + """ + And STDOUT should contain: + """ + Success: Deleted a total of + """ + + When I run `wp cron event schedule wp_cli_test_event_1 now hourly` + Then STDOUT should contain: + """ + Success: Scheduled event with hook 'wp_cli_test_event_1' + """ + + When I run `wp cron event schedule wp_cli_test_event_2 now hourly` + Then STDOUT should contain: + """ + Success: Scheduled event with hook 'wp_cli_test_event_2' + """ + + When I run `wp cron event schedule wp_cli_test_event_2 '+1 hour 5 minutes' hourly` + Then STDOUT should contain: + """ + Success: Scheduled event with hook 'wp_cli_test_event_2' + """ + + When I run `wp cron event delete wp_cli_test_event_2 --due-now` + Then STDOUT should contain: + """ + Deleted the cron event 'wp_cli_test_event_2' + """ + And STDOUT should contain: + """ + Deleted a total of + """ + + When I run `wp cron event list --hook=wp_cli_test_event_2 --format=count` + Then STDOUT should be: + """ + 1 + """ + + When I run `wp cron event delete --due-now` + Then STDOUT should contain: + """ + Deleted the cron event 'wp_cli_test_event_1' + """ + And STDOUT should not contain: + """ + Deleted the cron event 'wp_cli_test_event_2' + """ + And STDOUT should contain: + """ + Deleted a total of + """ + + Scenario: A valid combination of parameters should be present + When I try `wp cron event delete --due-now --all` + Then STDERR should be: + """ + Error: Please use either --due-now or --all. + """ + + When I try `wp cron event delete wp_cli_test_event_1 --all` + Then STDERR should be: + """ + Error: Please either specify cron events, or use --all. + """ diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index afad964c..1ef2b91b 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -221,46 +221,12 @@ public function schedule( $args, $assoc_args ) { */ public function run( $args, $assoc_args ) { - if ( empty( $args ) && ! Utils\get_flag_value( $assoc_args, 'due-now' ) && ! Utils\get_flag_value( $assoc_args, 'all' ) ) { - WP_CLI::error( 'Please specify one or more cron events, or use --due-now/--all.' ); - } - - $is_due_now = Utils\get_flag_value( $assoc_args, 'due-now' ); - - $events = self::get_cron_events( $is_due_now ); + $events = self::get_selected_cron_events( $args, $assoc_args ); if ( is_wp_error( $events ) ) { WP_CLI::error( $events ); } - $hooks = wp_list_pluck( $events, 'hook' ); - foreach ( $args as $hook ) { - if ( ! in_array( $hook, $hooks, true ) ) { - WP_CLI::error( sprintf( "Invalid cron event '%s'", $hook ) ); - } - } - - if ( Utils\get_flag_value( $assoc_args, 'due-now' ) ) { - $due_events = array(); - foreach ( $events as $event ) { - if ( ! empty( $args ) && ! in_array( $event->hook, $args, true ) ) { - continue; - } - if ( time() >= $event->time ) { - $due_events[] = $event; - } - } - $events = $due_events; - } elseif ( ! Utils\get_flag_value( $assoc_args, 'all' ) ) { - $due_events = array(); - foreach ( $events as $event ) { - if ( in_array( $event->hook, $args, true ) ) { - $due_events[] = $event; - } - } - $events = $due_events; - } - $executed = 0; foreach ( $events as $event ) { $start = microtime( true ); @@ -321,40 +287,19 @@ public function unschedule( $args, $assoc_args ) { } - /** - * Executes an event immediately. - * - * @param stdClass $event The event - * @return bool Whether the event was successfully executed or not. - */ - protected static function run_event( stdClass $event ) { - - if ( ! defined( 'DOING_CRON' ) ) { - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Using native WordPress constant. - define( 'DOING_CRON', true ); - } - - if ( false !== $event->schedule ) { - $new_args = array( $event->time, $event->schedule, $event->hook, $event->args ); - call_user_func_array( 'wp_reschedule_event', $new_args ); - } - - wp_unschedule_event( $event->time, $event->hook, $event->args ); - - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Can't prefix dynamic hooks here, calling registered hooks. - do_action_ref_array( $event->hook, $event->args ); - - return true; - - } - /** * Deletes all scheduled cron events for the given hook. * * ## OPTIONS * - * - * : The hook name. + * [...] + * : One or more hooks to delete. + * + * [--due-now] + * : Delete all hooks due right now. + * + * [--all] + * : Delete all hooks. * * ## EXAMPLES * @@ -363,9 +308,7 @@ protected static function run_event( stdClass $event ) { * Success: Deleted 2 instances of the cron event 'cron_test'. */ public function delete( $args, $assoc_args ) { - - $hook = $args[0]; - $events = self::get_cron_events(); + $events = self::get_selected_cron_events( $args, $assoc_args ); if ( is_wp_error( $events ) ) { WP_CLI::error( $events ); @@ -373,23 +316,41 @@ public function delete( $args, $assoc_args ) { $deleted = 0; foreach ( $events as $event ) { - if ( $event->hook === $hook ) { - $result = self::delete_event( $event ); - if ( $result ) { - $deleted++; - } else { - WP_CLI::warning( sprintf( "Failed to the delete the cron event '%s'.", $hook ) ); - } + $result = self::delete_event( $event ); + if ( $result ) { + $deleted++; + WP_CLI::log( sprintf( "Deleted the cron event '%s'", $event->hook ) ); } } - if ( $deleted ) { - $message = ( 1 === $deleted ) ? "Deleted the cron event '%2\$s'." : "Deleted %1\$d instances of the cron event '%2\$s'."; - WP_CLI::success( sprintf( $message, $deleted, $hook ) ); - } else { - WP_CLI::error( sprintf( "Invalid cron event '%s'.", $hook ) ); + $message = sprintf( 'Deleted a total of %d %s.', $deleted, Utils\pluralize( 'cron event', $deleted ) ); + WP_CLI::success( sprintf( $message, $deleted ) ); + } + + /** + * Executes an event immediately. + * + * @param stdClass $event The event + * @return bool Whether the event was successfully executed or not. + */ + protected static function run_event( stdClass $event ) { + + if ( ! defined( 'DOING_CRON' ) ) { + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Using native WordPress constant. + define( 'DOING_CRON', true ); + } + + if ( false !== $event->schedule ) { + wp_reschedule_event( $event->time, $event->schedule, $event->hook, $event->args ); } + wp_unschedule_event( $event->time, $event->hook, $event->args ); + + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Can't prefix dynamic hooks here, calling registered hooks. + do_action_ref_array( $event->hook, $event->args ); + + return true; + } /** @@ -478,6 +439,67 @@ protected static function get_cron_events( $is_due_now = false ) { } + /** + * Fetches an array of scheduled cron events selected by the user. + * + * @param array $args A list of event names + * @param array $assoc_args An associative list of CLI parameters + * + * @return array|WP_Error An array of objects, or a WP_Error object is there are no events scheduled. + */ + protected static function get_selected_cron_events( $args, $assoc_args ) { + $due_now = Utils\get_flag_value( $assoc_args, 'due-now' ); + $all = Utils\get_flag_value( $assoc_args, 'all' ); + + if ( empty( $args ) && ! $due_now && ! $all ) { + WP_CLI::error( 'Please specify one or more cron events, or use --due-now/--all.' ); + } + + if ( ! empty( $args ) && $all ) { + WP_CLI::error( 'Please either specify cron events, or use --all.' ); + } + + if ( $due_now && $all ) { + WP_CLI::error( 'Please use either --due-now or --all.' ); + } + + $events = self::get_cron_events(); + + if ( is_wp_error( $events ) ) { + return $events; + } + + $hooks = wp_list_pluck( $events, 'hook' ); + foreach ( $args as $hook ) { + if ( ! in_array( $hook, $hooks, true ) ) { + WP_CLI::error( sprintf( "Invalid cron event '%s'", $hook ) ); + } + } + + if ( $due_now ) { + $due_events = array(); + foreach ( $events as $event ) { + if ( ! empty( $args ) && ! in_array( $event->hook, $args, true ) ) { + continue; + } + if ( 'now' === $event->next_run_relative ) { + $due_events[] = $event; + } + } + $events = $due_events; + } elseif ( ! $all ) { + $due_events = array(); + foreach ( $events as $event ) { + if ( in_array( $event->hook, $args, true ) ) { + $due_events[] = $event; + } + } + $events = $due_events; + } + + return $events; + } + /** * Converts a time interval into human-readable format. * From 70ac6cab3ffb12587a492211749195545dfcbb9e Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Thu, 8 Jun 2023 12:36:22 +0300 Subject: [PATCH 2/9] Add support for --exclude --- features/cron.feature | 16 ++++++++++++++++ src/Cron_Event_Command.php | 35 +++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/features/cron.feature b/features/cron.feature index 626e9ad8..6b97f62d 100644 --- a/features/cron.feature +++ b/features/cron.feature @@ -479,6 +479,22 @@ Feature: Manage WP-Cron events and schedules Deleted a total of """ + When I run `wp cron event schedule wp_cli_test_event_1 '+1 hour 5 minutes' hourly` + Then STDOUT should not be empty + + When I run `wp cron event schedule wp_cli_test_event_2 '+1 hour 5 minutes' hourly` + Then STDOUT should not be empty + + When I run `wp cron event delete --all --exclude=wp_cli_test_event_1` + Then STDOUT should contain: + """ + Deleted the cron event 'wp_cli_test_event_2' + """ + And STDOUT should contain: + """ + Deleted a total of + """ + Scenario: A valid combination of parameters should be present When I try `wp cron event delete --due-now --all` Then STDERR should be: diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index db64afc0..58355963 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -230,22 +230,6 @@ public function run( $args, $assoc_args ) { WP_CLI::error( $events ); } - $exclude = Utils\get_flag_value( $assoc_args, 'exclude' ); - - if ( ! empty( $exclude ) ) { - $exclude = explode( ',', $exclude ); - - $events = array_filter( - $events, - function ( $event ) use ( $args, $exclude ) { - if ( in_array( $event->hook, $exclude, true ) ) { - return false; - } - return true; - } - ); - } - $executed = 0; foreach ( $events as $event ) { $start = microtime( true ); @@ -317,6 +301,9 @@ public function unschedule( $args, $assoc_args ) { * [--due-now] * : Delete all hooks due right now. * + * [--exclude=] + * : Comma-separated list of hooks to exclude. + * * [--all] * : Delete all hooks. * @@ -469,6 +456,7 @@ protected static function get_cron_events( $is_due_now = false ) { protected static function get_selected_cron_events( $args, $assoc_args ) { $due_now = Utils\get_flag_value( $assoc_args, 'due-now' ); $all = Utils\get_flag_value( $assoc_args, 'all' ); + $exclude = Utils\get_flag_value( $assoc_args, 'exclude' ); if ( empty( $args ) && ! $due_now && ! $all ) { WP_CLI::error( 'Please specify one or more cron events, or use --due-now/--all.' ); @@ -495,6 +483,19 @@ protected static function get_selected_cron_events( $args, $assoc_args ) { } } + // Remove all excluded hooks + if ( ! empty( $exclude ) ) { + $exclude = explode( ',', $exclude ); + $events = array_filter( + $events, + function ( $event ) use ( $exclude ) { + return ! in_array( $event->hook, $exclude, true ); + } + ); + } + + // If --due-now is specified, take only the events that have 'now' as + // their next_run_relative time if ( $due_now ) { $due_events = array(); foreach ( $events as $event ) { @@ -507,6 +508,8 @@ protected static function get_selected_cron_events( $args, $assoc_args ) { } $events = $due_events; } elseif ( ! $all ) { + // IF --all is not specified, take only the events that have been + // given as $args. $due_events = array(); foreach ( $events as $event ) { if ( in_array( $event->hook, $args, true ) ) { From c00646e7a8ebb6e8846e733339bfc5b897c653fd Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Thu, 8 Jun 2023 13:37:44 +0100 Subject: [PATCH 3/9] Minor comments fixes --- src/Cron_Event_Command.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 58355963..35d83d0a 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -483,7 +483,7 @@ protected static function get_selected_cron_events( $args, $assoc_args ) { } } - // Remove all excluded hooks + // Remove all excluded hooks. if ( ! empty( $exclude ) ) { $exclude = explode( ',', $exclude ); $events = array_filter( @@ -495,7 +495,7 @@ function ( $event ) use ( $exclude ) { } // If --due-now is specified, take only the events that have 'now' as - // their next_run_relative time + // their next_run_relative time. if ( $due_now ) { $due_events = array(); foreach ( $events as $event ) { @@ -508,7 +508,7 @@ function ( $event ) use ( $exclude ) { } $events = $due_events; } elseif ( ! $all ) { - // IF --all is not specified, take only the events that have been + // If --all is not specified, take only the events that have been // given as $args. $due_events = array(); foreach ( $events as $event ) { From d4997d31f45b8e69154584b5edbf418133c59ecc Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Thu, 8 Jun 2023 16:09:55 +0300 Subject: [PATCH 4/9] Do not log every deleted cron event --- features/cron.feature | 46 ++++++++++++++++++++++---------------- src/Cron_Event_Command.php | 1 - 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/features/cron.feature b/features/cron.feature index 6b97f62d..e8fabbb1 100644 --- a/features/cron.feature +++ b/features/cron.feature @@ -37,7 +37,6 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete wp_cli_test_event_1` Then STDOUT should contain: """ - Deleted the cron event 'wp_cli_test_event_1' Success: Deleted a total of 1 cron event. """ @@ -124,8 +123,6 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete wp_cli_test_event_5` Then STDOUT should be: """ - Deleted the cron event 'wp_cli_test_event_5' - Deleted the cron event 'wp_cli_test_event_5' Success: Deleted a total of 2 cron events. """ @@ -177,7 +174,6 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete wp_cli_test_event_2` Then STDOUT should contain: """ - Deleted the cron event 'wp_cli_test_event_2' Success: Deleted a total of 1 cron event. """ @@ -420,15 +416,17 @@ Feature: Manage WP-Cron events and schedules When I try `wp cron event delete --all` Then STDOUT should contain: """ - Deleted the cron event 'wp_cli_test_event_1' + Success: Deleted a total of """ - And STDOUT should contain: + + When I try `wp cron event list` + Then STDOUT should not contain: """ - Deleted the cron event 'wp_cli_test_event_2' + wp_cli_test_event_1 """ - And STDOUT should contain: + And STDOUT should not contain: """ - Success: Deleted a total of + wp_cli_test_event_2 """ When I run `wp cron event schedule wp_cli_test_event_1 now hourly` @@ -452,11 +450,13 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete wp_cli_test_event_2 --due-now` Then STDOUT should contain: """ - Deleted the cron event 'wp_cli_test_event_2' + Deleted a total of 1 cron event """ - And STDOUT should contain: + + When I try `wp cron event list` + Then STDOUT should contain: """ - Deleted a total of + wp_cli_test_event_2 """ When I run `wp cron event list --hook=wp_cli_test_event_2 --format=count` @@ -468,15 +468,17 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete --due-now` Then STDOUT should contain: """ - Deleted the cron event 'wp_cli_test_event_1' + Success: Deleted a total of """ - And STDOUT should not contain: + + When I try `wp cron event list` + Then STDOUT should not contain: """ - Deleted the cron event 'wp_cli_test_event_2' + wp_cli_test_event_1 """ And STDOUT should contain: """ - Deleted a total of + wp_cli_test_event_2 """ When I run `wp cron event schedule wp_cli_test_event_1 '+1 hour 5 minutes' hourly` @@ -488,16 +490,22 @@ Feature: Manage WP-Cron events and schedules When I run `wp cron event delete --all --exclude=wp_cli_test_event_1` Then STDOUT should contain: """ - Deleted the cron event 'wp_cli_test_event_2' + Success: Deleted a total of + """ + + When I try `wp cron event list` + Then STDOUT should not contain: + """ + wp_cli_test_event_2 """ And STDOUT should contain: """ - Deleted a total of + wp_cli_test_event_1 """ Scenario: A valid combination of parameters should be present When I try `wp cron event delete --due-now --all` - Then STDERR should be: + Then STDERR should be: """ Error: Please use either --due-now or --all. """ diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 58355963..ee922d54 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -325,7 +325,6 @@ public function delete( $args, $assoc_args ) { $result = self::delete_event( $event ); if ( $result ) { $deleted++; - WP_CLI::log( sprintf( "Deleted the cron event '%s'", $event->hook ) ); } } From ca61e8c27979d84aa226d0f65287bdabfebe907a Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Fri, 9 Jun 2023 10:11:05 +0300 Subject: [PATCH 5/9] Restore punctuation in test --- features/cron.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/cron.feature b/features/cron.feature index e8fabbb1..700df62b 100644 --- a/features/cron.feature +++ b/features/cron.feature @@ -135,7 +135,7 @@ Feature: Manage WP-Cron events and schedules When I try `wp cron event delete wp_cli_test_event_5` Then STDERR should be: """ - Error: Invalid cron event 'wp_cli_test_event_5' + Error: Invalid cron event 'wp_cli_test_event_5'. """ Scenario: Scheduling and then running a re-occurring event From 80bf340943a08f1d568985aa21c94987b8cd79b1 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Sat, 10 Jun 2023 14:37:36 +0300 Subject: [PATCH 6/9] Remove punctuation --- features/cron.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/cron.feature b/features/cron.feature index 700df62b..e8fabbb1 100644 --- a/features/cron.feature +++ b/features/cron.feature @@ -135,7 +135,7 @@ Feature: Manage WP-Cron events and schedules When I try `wp cron event delete wp_cli_test_event_5` Then STDERR should be: """ - Error: Invalid cron event 'wp_cli_test_event_5'. + Error: Invalid cron event 'wp_cli_test_event_5' """ Scenario: Scheduling and then running a re-occurring event From c689102403b38e044feeb8ac130e74861378900a Mon Sep 17 00:00:00 2001 From: Jan Willem Oostendorp Date: Fri, 10 Nov 2023 17:41:52 +0100 Subject: [PATCH 7/9] Synced changes. Now behat passes. --- src/Cron_Event_Command.php | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 8cccea5f..66758e2e 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -287,32 +287,6 @@ public function unschedule( $args, $assoc_args ) { } } - /** - * Executes an event immediately. - * - * @param stdClass $event The event - * @return bool Whether the event was successfully executed or not. - */ - protected static function run_event( stdClass $event ) { - - if ( ! defined( 'DOING_CRON' ) ) { - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Using native WordPress constant. - define( 'DOING_CRON', true ); - } - - if ( false !== $event->schedule ) { - $new_args = array( $event->time, $event->schedule, $event->hook, $event->args ); - call_user_func_array( 'wp_reschedule_event', $new_args ); - } - - wp_unschedule_event( $event->time, $event->hook, $event->args ); - - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Can't prefix dynamic hooks here, calling registered hooks. - do_action_ref_array( $event->hook, $event->args ); - - return true; - } - /** * Deletes all scheduled cron events for the given hook. * @@ -345,13 +319,11 @@ public function delete( $args, $assoc_args ) { $deleted = 0; foreach ( $events as $event ) { - if ( $event->hook === $hook ) { - $result = self::delete_event( $event ); - if ( $result ) { - ++$deleted; - } else { - WP_CLI::warning( sprintf( "Failed to the delete the cron event '%s'.", $hook ) ); - } + $result = self::delete_event( $event ); + if ( $result ) { + ++$deleted; + } else { + WP_CLI::warning( sprintf( "Failed to the delete the cron event '%s'.", $hook ) ); } } From 6b2fce3691f7a6eeb4baa47e7472bc5c8a1eda1e Mon Sep 17 00:00:00 2001 From: Jan Willem Oostendorp Date: Fri, 10 Nov 2023 17:58:35 +0100 Subject: [PATCH 8/9] Fixed a undefined variable. --- src/Cron_Event_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 66758e2e..4a7f96ed 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -323,7 +323,7 @@ public function delete( $args, $assoc_args ) { if ( $result ) { ++$deleted; } else { - WP_CLI::warning( sprintf( "Failed to the delete the cron event '%s'.", $hook ) ); + WP_CLI::warning( sprintf( "Failed to the delete the cron event '%s'.", $event->hook ) ); } } From 3020b5ad7dd1b8b19ffa67ca985687e5ad04b3b3 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Tue, 13 Feb 2024 13:58:44 -0800 Subject: [PATCH 9/9] Regenerate README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4be21467..6e29a082 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ wp cron event Deletes all scheduled cron events for the given hook. ~~~ -wp cron event delete [...] [--due-now] [--all] +wp cron event delete [...] [--due-now] [--exclude=] [--all] ~~~ **OPTIONS** @@ -97,6 +97,9 @@ wp cron event delete [...] [--due-now] [--all] [--due-now] Delete all hooks due right now. + [--exclude=] + Comma-separated list of hooks to exclude. + [--all] Delete all hooks.