From ccbd16fef10fc88a790ccd56e0c44f2740243d34 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 19 Aug 2021 12:44:57 +0000 Subject: [PATCH] Media: Check the return type of `_get_cron_array()` in `WP_Media_List_Table::prepare_items()`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following warnings could, in very select circumstances, be shown: {{{ // PHP 8.0 and higher: Warning: foreach() argument must be of type array|object, bool given // PHP 5.6 – 7.4 Warning: Invalid argument supplied for foreach() }}} In `WP_Media_List_Table::prepare_items()`, the cron info array is retrieved via a call to `_get_cron_array()`, but as the documentation (correctly) states, the return type of that function is `array|false`, where `false` is returned for a virgin site, with no cron jobs scheduled yet. However, no type check is done on the return value, and the method just blindly continues by using it in a `foreach`. Fixed by adding validation for the returned value from `_get_cron_array()` and only running the `foreach` when the returned value is an array. Reference: [https://developer.wordpress.org/reference/functions/_get_cron_array/ WordPress Developer Resources: _get_cron_array()] Follow-up to [48417]. Props jrf, hellofromTonya, mukesh27. Fixes #53949. Built from https://develop.svn.wordpress.org/trunk@51638 git-svn-id: http://core.svn.wordpress.org/trunk@51244 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-media-list-table.php | 14 +++++++++----- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/wp-admin/includes/class-wp-media-list-table.php b/wp-admin/includes/class-wp-media-list-table.php index b3eb0b32cc..275d07caca 100644 --- a/wp-admin/includes/class-wp-media-list-table.php +++ b/wp-admin/includes/class-wp-media-list-table.php @@ -78,12 +78,16 @@ class WP_Media_List_Table extends WP_List_Table { */ $not_in = array(); - foreach ( _get_cron_array() as $cron ) { - if ( isset( $cron['upgrader_scheduled_cleanup'] ) ) { - $details = reset( $cron['upgrader_scheduled_cleanup'] ); + $crons = _get_cron_array(); - if ( ! empty( $details['args'][0] ) ) { - $not_in[] = (int) $details['args'][0]; + if ( is_array( $crons ) ) { + foreach ( $crons as $cron ) { + if ( isset( $cron['upgrader_scheduled_cleanup'] ) ) { + $details = reset( $cron['upgrader_scheduled_cleanup'] ); + + if ( ! empty( $details['args'][0] ) ) { + $not_in[] = (int) $details['args'][0]; + } } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 2c931ecfc2..71bf87b302 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51637'; +$wp_version = '5.9-alpha-51638'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.