From 7ee70968ceeb90d792bb6bd3d40371b6bd271300 Mon Sep 17 00:00:00 2001 From: nbachiyski Date: Mon, 3 May 2010 22:07:31 +0000 Subject: [PATCH] Refactor get_available_languages() to use glob() instead of *dir functions. See #13023 git-svn-id: http://svn.automattic.com/wordpress/trunk@14417 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/l10n.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 6dedf30bd..7a4ea8fcd 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -491,20 +491,13 @@ function translate_user_role( $name ) { * @return array Array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names. */ function get_available_languages( $dir = null ) { - $languages = array(); - - if ( empty($dir) ) - $dir = WP_LANG_DIR; - - if ( is_dir( $dir ) && $dh = opendir( $dir ) ) { - while ( ( $lang_file = readdir( $dh ) ) !== false ) { - if ( substr( $lang_file, -3 ) == '.mo' && ( false === strpos( $lang_file, 'continents-cities' ) ) ) - $languages[] = basename($lang_file, '.mo'); + $languages = array(); + + foreach( glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ) as $lang_file ) { + if ( false === strpos( $lang_file, 'continents-cities' ) ) { + $languages[] = basename($lang_file, '.mo'); } - closedir($dh); } - + return $languages; -} - -?> +} \ No newline at end of file