diff --git a/composer.json b/composer.json index 969d20a8..37127c09 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ }, "require-dev": { "wp-cli/entity-command": "^1.3 || ^2", + "wp-cli/eval-command": "^2.0", "wp-cli/server-command": "^2.0", "wp-cli/wp-cli-tests": "^3.1" }, diff --git a/features/cron.feature b/features/cron.feature index e605bcfd..86981138 100644 --- a/features/cron.feature +++ b/features/cron.feature @@ -360,3 +360,41 @@ Feature: Manage WP-Cron events and schedules Then STDOUT should be CSV containing: | hook | recurrence | args | | wp_cli_test_args_event | Non-repeating | {"foo":"banana","bar":"apple"} | + + Scenario: Warn when an invalid cron event is detected + Given a WP install + And a update.php file: + """ + array( + 'postindexer_secondpass_cron' => array( + '40cd750bba9870f18aada2478b24840a' => array( + 'schedule' => '5mins', + 'args' => array(), + 'interval' => 100, + ), + ), + ), + 'wp_batch_split_terms' => array( + 1442323165 => array( + '40cd750bba9870f18aada2478b24840a' => array( + 'schedule' => false, + 'args' => array() + ) + ) + ) + ); + update_option( 'cron', $val ); + """ + And I run `wp eval-file update.php` + + When I try `wp cron event list` + Then STDOUT should contain: + """ + postindexer_secondpass_cron + """ + And STDERR should contain: + """ + Warning: Ignoring incorrectly registered cron event "wp_batch_split_terms". + """ diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 3665b144..afad964c 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -449,6 +449,13 @@ protected static function get_cron_events( $is_due_now = false ) { } foreach ( $crons as $time => $hooks ) { + + // Incorrectly registered cron events can produce a string key. + if ( is_string( $time ) ) { + WP_CLI::warning( sprintf( 'Ignoring incorrectly registered cron event "%s".', $time ) ); + continue; + } + foreach ( $hooks as $hook => $hook_events ) { foreach ( $hook_events as $sig => $data ) {