From 3f2b0779f59817f0b65e2f74647233c21a7802dc Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Mon, 27 Jul 2015 18:04:19 +0000 Subject: [PATCH] Don't blindly trust the output of `glob()` to be an array. props kitchin fixes #33093 git-svn-id: https://develop.svn.wordpress.org/trunk@33447 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-upgrader.php | 13 ++++++++----- src/wp-admin/includes/update-core.php | 7 +++++-- src/wp-includes/l10n.php | 14 +++++++++----- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/wp-admin/includes/class-wp-upgrader.php b/src/wp-admin/includes/class-wp-upgrader.php index 0ab08b6125..019bb47a70 100644 --- a/src/wp-admin/includes/class-wp-upgrader.php +++ b/src/wp-admin/includes/class-wp-upgrader.php @@ -1058,11 +1058,14 @@ class Plugin_Upgrader extends WP_Upgrader { // Check the folder contains at least 1 valid plugin. $plugins_found = false; - foreach ( glob( $working_directory . '*.php' ) as $file ) { - $info = get_plugin_data($file, false, false); - if ( !empty( $info['Name'] ) ) { - $plugins_found = true; - break; + $files = glob( $working_directory . '*.php' ); + if ( $files ) { + foreach ( $files as $file ) { + $info = get_plugin_data( $file, false, false ); + if ( ! empty( $info['Name'] ) ) { + $plugins_found = true; + break; + } } } diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php index f6fee79c72..0cb824a79a 100644 --- a/src/wp-admin/includes/update-core.php +++ b/src/wp-admin/includes/update-core.php @@ -1273,8 +1273,11 @@ function _upgrade_422_find_genericons_files_in_folder( $directory ) { $files[] = "{$directory}example.html"; } - foreach ( glob( $directory . '*', GLOB_ONLYDIR ) as $dir ) { - $files = array_merge( $files, _upgrade_422_find_genericons_files_in_folder( $dir ) ); + $dirs = glob( $directory . '*', GLOB_ONLYDIR ); + if ( $dirs ) { + foreach ( $dirs as $dir ) { + $files = array_merge( $files, _upgrade_422_find_genericons_files_in_folder( $dir ) ); + } } return $files; diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index 7366e58afb..7caf879059 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -774,11 +774,15 @@ function translate_user_role( $name ) { function get_available_languages( $dir = null ) { $languages = array(); - foreach( (array)glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ) as $lang_file ) { - $lang_file = basename($lang_file, '.mo'); - if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) && - 0 !== strpos( $lang_file, 'admin-' )) - $languages[] = $lang_file; + $lang_files = glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ); + if ( $lang_files ) { + foreach( $lang_files as $lang_file ) { + $lang_file = basename( $lang_file, '.mo' ); + if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) && + 0 !== strpos( $lang_file, 'admin-' ) ) { + $languages[] = $lang_file; + } + } } return $languages;