Skip to content

Commit 8b66c44

Browse files
authored
Merge pull request #93 from wp-cli/92-warn-invalid-cron-event
2 parents 1ca3736 + e8ac723 commit 8b66c44

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"require-dev": {
1818
"wp-cli/entity-command": "^1.3 || ^2",
19+
"wp-cli/eval-command": "^2.0",
1920
"wp-cli/server-command": "^2.0",
2021
"wp-cli/wp-cli-tests": "^3.1"
2122
},

features/cron.feature

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,41 @@ Feature: Manage WP-Cron events and schedules
360360
Then STDOUT should be CSV containing:
361361
| hook | recurrence | args |
362362
| wp_cli_test_args_event | Non-repeating | {"foo":"banana","bar":"apple"} |
363+
364+
Scenario: Warn when an invalid cron event is detected
365+
Given a WP install
366+
And a update.php file:
367+
"""
368+
<?php
369+
$val = array(
370+
1647914509 => array(
371+
'postindexer_secondpass_cron' => array(
372+
'40cd750bba9870f18aada2478b24840a' => array(
373+
'schedule' => '5mins',
374+
'args' => array(),
375+
'interval' => 100,
376+
),
377+
),
378+
),
379+
'wp_batch_split_terms' => array(
380+
1442323165 => array(
381+
'40cd750bba9870f18aada2478b24840a' => array(
382+
'schedule' => false,
383+
'args' => array()
384+
)
385+
)
386+
)
387+
);
388+
update_option( 'cron', $val );
389+
"""
390+
And I run `wp eval-file update.php`
391+
392+
When I try `wp cron event list`
393+
Then STDOUT should contain:
394+
"""
395+
postindexer_secondpass_cron
396+
"""
397+
And STDERR should contain:
398+
"""
399+
Warning: Ignoring incorrectly registered cron event "wp_batch_split_terms".
400+
"""

src/Cron_Event_Command.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,13 @@ protected static function get_cron_events( $is_due_now = false ) {
449449
}
450450

451451
foreach ( $crons as $time => $hooks ) {
452+
453+
// Incorrectly registered cron events can produce a string key.
454+
if ( is_string( $time ) ) {
455+
WP_CLI::warning( sprintf( 'Ignoring incorrectly registered cron event "%s".', $time ) );
456+
continue;
457+
}
458+
452459
foreach ( $hooks as $hook => $hook_events ) {
453460
foreach ( $hook_events as $sig => $data ) {
454461

0 commit comments

Comments
 (0)