From 839d20f9c53010c1a27dc63bf7451f5aa490e368 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 29 Jul 2022 03:34:13 +0000 Subject: [PATCH] Cron API: Modify `_get_cron_array()` to always return an array. Change the return type of `_get_cron_array()` to an empty array if the `cron` option is either missing or of an unexpected type. This change ensures the return value for no registered events is consistently an empty array. Previously the return value could be either an empty array or `false`. Props thakkarhardik, jrf, costdev. Fixes #53940. Built from https://develop.svn.wordpress.org/trunk@53791 git-svn-id: http://core.svn.wordpress.org/trunk@53350 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/cron.php | 14 +++----------- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/wp-includes/cron.php b/wp-includes/cron.php index 83cbb8b9d0..1577dab9a6 100644 --- a/wp-includes/cron.php +++ b/wp-includes/cron.php @@ -119,9 +119,6 @@ function wp_schedule_single_event( $timestamp, $hook, $args = array(), $wp_error * are considered duplicates. */ $crons = _get_cron_array(); - if ( ! is_array( $crons ) ) { - $crons = array(); - } $key = md5( serialize( $event->args ) ); $duplicate = false; @@ -306,9 +303,6 @@ function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array(), $wp $key = md5( serialize( $event->args ) ); $crons = _get_cron_array(); - if ( ! is_array( $crons ) ) { - $crons = array(); - } $crons[ $event->timestamp ][ $event->hook ][ $key ] = array( 'schedule' => $event->schedule, @@ -1133,9 +1127,6 @@ function wp_get_ready_cron_jobs() { } $crons = _get_cron_array(); - if ( ! is_array( $crons ) ) { - return array(); - } $gmt_time = microtime( true ); $keys = array_keys( $crons ); @@ -1162,14 +1153,15 @@ function wp_get_ready_cron_jobs() { * Retrieve cron info array option. * * @since 2.1.0 + * @since 6.1.0 Return type modified to consistenty return an array. * @access private * - * @return array[]|false Array of cron info arrays on success, false on failure. + * @return array[] Array of cron events. */ function _get_cron_array() { $cron = get_option( 'cron' ); if ( ! is_array( $cron ) ) { - return false; + return array(); } if ( ! isset( $cron['version'] ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 1f94011151..3d1c156620 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53790'; +$wp_version = '6.1-alpha-53791'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.