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.


git-svn-id: https://develop.svn.wordpress.org/trunk@53791 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2022-07-29 03:32:58 +00:00
parent 7b43b08dd5
commit a091693f9a
4 changed files with 130 additions and 14 deletions
+3 -11
View File
@@ -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'] ) ) {