From db11c6f72f87a4d9b984fb34ea8c5e55a3b463f0 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 16 Mar 2026 22:47:56 +0100 Subject: [PATCH 1/4] Pass `$due_now` --- 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 5a5df5b0..1e9b8952 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -562,7 +562,7 @@ protected static function get_selected_cron_events( $args, $assoc_args ) { WP_CLI::error( 'Please use either --due-now or --all.' ); } - $events = self::get_cron_events(); + $events = self::get_cron_events( $due_now ); if ( is_wp_error( $events ) ) { return $events; From 86c2b76af9aac12e568d4ea23ea91f74b3e8b692 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 08:20:05 +0100 Subject: [PATCH 2/4] Fix `unschedule` command failing on WordPress 4.9 (#135) * Initial plan * Fix unschedule for WP 4.9 compatibility Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Cron_Event_Command.php | 46 +++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 1e9b8952..60c71210 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -307,28 +307,38 @@ public function unschedule( $args, $assoc_args ) { list( $hook ) = $args; - $unscheduled = wp_unschedule_hook( $hook ); - - if ( empty( $unscheduled ) ) { - $message = 'Failed to unschedule events for hook \'%1\$s.'; - - // If 0 event found on hook. - if ( 0 === $unscheduled ) { - $message = "No events found for hook '%1\$s'."; + // Count events before unscheduling for WP < 5.1 compatibility where + // wp_unschedule_hook() returns null instead of the event count. + $crons = _get_cron_array(); + $event_count = 0; + if ( is_array( $crons ) ) { + foreach ( $crons as $cron ) { + if ( isset( $cron[ $hook ] ) ) { + $event_count += count( $cron[ $hook ] ); + } } + } - WP_CLI::error( sprintf( $message, $hook ) ); + if ( 0 === $event_count ) { + WP_CLI::error( sprintf( "No events found for hook '%s'.", $hook ) ); + } - } else { - WP_CLI::success( - sprintf( - 'Unscheduled %1$d %2$s for hook \'%3$s\'.', - $unscheduled, - Utils\pluralize( 'event', $unscheduled ), - $hook - ) - ); + $unscheduled = wp_unschedule_hook( $hook ); + + if ( false === $unscheduled ) { + WP_CLI::error( sprintf( "Failed to unschedule events for hook '%s'.", $hook ) ); } + + $count = ( is_int( $unscheduled ) && $unscheduled > 0 ) ? $unscheduled : $event_count; + + WP_CLI::success( + sprintf( + 'Unscheduled %1$d %2$s for hook \'%3$s\'.', + $count, + Utils\pluralize( 'event', $count ), + $hook + ) + ); } /** From d741fea65ff6e17658565d778f9ae9651010b180 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 17 Mar 2026 08:26:38 +0100 Subject: [PATCH 3/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/Cron_Event_Command.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 60c71210..60773c9b 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -313,6 +313,9 @@ public function unschedule( $args, $assoc_args ) { $event_count = 0; if ( is_array( $crons ) ) { foreach ( $crons as $cron ) { + if ( ! is_array( $cron ) ) { + continue; + } if ( isset( $cron[ $hook ] ) ) { $event_count += count( $cron[ $hook ] ); } From e8c6c04f0a93debacda8f98be1566810c1be5cad Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 17 Mar 2026 09:28:27 +0100 Subject: [PATCH 4/4] PHPStan fix --- src/Cron_Event_Command.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 60773c9b..561dee57 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -316,6 +316,9 @@ public function unschedule( $args, $assoc_args ) { if ( ! is_array( $cron ) ) { continue; } + /** + * @var array> $cron + */ if ( isset( $cron[ $hook ] ) ) { $event_count += count( $cron[ $hook ] ); }