get_available_languages

The timeline below displays how wordpress function get_available_languages has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Gets all available languages based on the presence of *.mo and *.l10n.php files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
 * @since 6.5.0 The initial file list is now cached and also takes into account *.l10n.php files.
 *
 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry.
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return string[] An array of language codes or an empty array if no languages are present.
 *                  Language codes are formed by stripping the file extension from the language file names.
 */
function get_available_languages($dir = null)
{
    global $wp_textdomain_registry;
    $languages = array();
    $path = is_null($dir) ? WP_LANG_DIR : $dir;
    $lang_files = $wp_textdomain_registry->get_language_files_from_path($path);
    if ($lang_files) {
        foreach ($lang_files as $lang_file) {
            $lang_file = basename($lang_file, '.mo');
            $lang_file = basename($lang_file, '.l10n.php');
            if (!str_starts_with($lang_file, 'continents-cities') && !str_starts_with($lang_file, 'ms-') && !str_starts_with($lang_file, 'admin-')) {
                $languages[] = $lang_file;
            }
        }
    }
    /**
     * Filters the list of available language codes.
     *
     * @since 4.7.0
     *
     * @param string[] $languages An array of available language codes.
     * @param string   $dir       The directory where the language files were found.
     */
    return apply_filters('get_available_languages', array_unique($languages), $dir);
}

WordPress Version: 6.3

/**
 * Gets all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return string[] An 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();
    $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 (!str_starts_with($lang_file, 'continents-cities') && !str_starts_with($lang_file, 'ms-') && !str_starts_with($lang_file, 'admin-')) {
                $languages[] = $lang_file;
            }
        }
    }
    /**
     * Filters the list of available language codes.
     *
     * @since 4.7.0
     *
     * @param string[] $languages An array of available language codes.
     * @param string   $dir       The directory where the language files were found.
     */
    return apply_filters('get_available_languages', $languages, $dir);
}

WordPress Version: 6.2

/**
 * Gets all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return string[] An 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();
    $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;
            }
        }
    }
    /**
     * Filters the list of available language codes.
     *
     * @since 4.7.0
     *
     * @param string[] $languages An array of available language codes.
     * @param string   $dir       The directory where the language files were found.
     */
    return apply_filters('get_available_languages', $languages, $dir);
}

WordPress Version: 6.1

/**
 * Gets all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return string[] An 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();
    $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;
            }
        }
    }
    /**
     * Filters the list of available language codes.
     *
     * @since 4.7.0
     *
     * @param string[] $languages An array of available language codes.
     * @param string   $dir       The directory where the language files were found.
     */
    return apply_filters('get_available_languages', $languages, $dir);
}

WordPress Version: 5.4

/**
 * Get all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return string[] An 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();
    $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;
            }
        }
    }
    /**
     * Filters the list of available language codes.
     *
     * @since 4.7.0
     *
     * @param string[] $languages An array of available language codes.
     * @param string   $dir       The directory where the language files were found.
     */
    return apply_filters('get_available_languages', $languages, $dir);
}

WordPress Version: 4.7

/**
 * Get all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return array An 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();
    $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;
            }
        }
    }
    /**
     * Filters the list of available language codes.
     *
     * @since 4.7.0
     *
     * @param array  $languages An array of available language codes.
     * @param string $dir       The directory where the language files were found.
     */
    return apply_filters('get_available_languages', $languages, $dir);
}

WordPress Version: .30

/**
 * Get all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return array An 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();
    $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;
}

WordPress Version: 2.3

/**
 * Get all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return array An 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();
    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;
        }
    }
    return $languages;
}

WordPress Version: .20

/**
 * Get all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return array An 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();
    $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;
}

WordPress Version: 2.2

/**
 * Get all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return array An 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();
    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;
        }
    }
    return $languages;
}

WordPress Version: .10

/**
 * Get all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return array An 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();
    $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;
}

WordPress Version: 3.7

/**
 * Get all available languages based on the presence of *.mo files in a given directory.
 *
 * The default directory is WP_LANG_DIR.
 *
 * @since 3.0.0
 *
 * @param string $dir A directory to search for language files.
 *                    Default WP_LANG_DIR.
 * @return array An 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();
    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;
        }
    }
    return $languages;
}