diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index b3eb0b32cc..275d07caca 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/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/tests/phpunit/tests/admin/includesMediaListTable.php b/tests/phpunit/tests/admin/includesMediaListTable.php new file mode 100644 index 0000000000..da0aef19f2 --- /dev/null +++ b/tests/phpunit/tests/admin/includesMediaListTable.php @@ -0,0 +1,50 @@ +getMockBuilder( WP_Media_List_Table::class ) + ->disableOriginalConstructor() + ->disallowMockingUnknownTypes() + ->setMethods( array( 'set_pagination_args' ) ) + ->getMock(); + + $mock->expects( $this->once() ) + ->method( 'set_pagination_args' ); + + $wp_query->query_vars['posts_per_page'] = 10; + delete_option( 'cron' ); + + // Verify that the cause of the error is in place. + $this->assertFalse( _get_cron_array(), '_get_cron_array() does not return false' ); + + // If this test does not error out due to the PHP warning, we're good. + $mock->prepare_items(); + } +}