wp/wp-includes/cron.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-includes/cron.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/cron.php	Tue Sep 27 16:37:53 2022 +0200
@@ -118,7 +118,11 @@
 	 * current time) all events scheduled within the next ten minutes
 	 * are considered duplicates.
 	 */
-	$crons     = (array) _get_cron_array();
+	$crons = _get_cron_array();
+	if ( ! is_array( $crons ) ) {
+		$crons = array();
+	}
+
 	$key       = md5( serialize( $event->args ) );
 	$duplicate = false;
 
@@ -302,6 +306,10 @@
 	$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,
 		'args'     => $event->args,
@@ -1032,7 +1040,7 @@
  * @since 2.1.0
  * @since 5.4.0 The 'weekly' schedule was added.
  *
- * @return array
+ * @return array[]
  */
 function wp_get_schedules() {
 	$schedules = array(
@@ -1059,7 +1067,7 @@
 	 *
 	 * @since 2.1.0
 	 *
-	 * @param array $new_schedules An array of non-default cron schedules. Default empty.
+	 * @param array[] $new_schedules An array of non-default cron schedule arrays. Default empty.
 	 */
 	return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
 }
@@ -1105,7 +1113,7 @@
  *
  * @since 5.1.0
  *
- * @return array Cron jobs ready to be run.
+ * @return array[] Array of cron job arrays ready to be run.
  */
 function wp_get_ready_cron_jobs() {
 	/**
@@ -1116,8 +1124,8 @@
 	 *
 	 * @since 5.1.0
 	 *
-	 * @param null|array $pre Array of ready cron tasks to return instead. Default null
-	 *                        to continue using results from _get_cron_array().
+	 * @param null|array[] $pre Array of ready cron tasks to return instead. Default null
+	 *                          to continue using results from _get_cron_array().
 	 */
 	$pre = apply_filters( 'pre_get_ready_cron_jobs', null );
 	if ( null !== $pre ) {
@@ -1125,8 +1133,7 @@
 	}
 
 	$crons = _get_cron_array();
-
-	if ( false === $crons ) {
+	if ( ! is_array( $crons ) ) {
 		return array();
 	}
 
@@ -1157,7 +1164,7 @@
  * @since 2.1.0
  * @access private
  *
- * @return array|false Cron info array on success, false on failure.
+ * @return array[]|false Array of cron info arrays on success, false on failure.
  */
 function _get_cron_array() {
 	$cron = get_option( 'cron' );
@@ -1183,11 +1190,15 @@
  *
  * @access private
  *
- * @param array $cron     Cron info array from _get_cron_array().
- * @param bool  $wp_error Optional. Whether to return a WP_Error on failure. Default false.
+ * @param array[] $cron     Array of cron info arrays from _get_cron_array().
+ * @param bool    $wp_error Optional. Whether to return a WP_Error on failure. Default false.
  * @return bool|WP_Error True if cron array updated. False or WP_Error on failure.
  */
 function _set_cron_array( $cron, $wp_error = false ) {
+	if ( ! is_array( $cron ) ) {
+		$cron = array();
+	}
+
 	$cron['version'] = 2;
 	$result          = update_option( 'cron', $cron );