get_available_languages( string $dir = null ): string[]
- Since
- 3.0.0, 4.7.0, 6.5.0
- Source
wp-includes/l10n.php:1478
Gets all available languages based on the presence of *.mo and *.l10n.php files in a given directory.
Description
The default directory is WP_LANG_DIR.
Parameters
$dirstringoptional- A directory to search for language files. Default WP_LANG_DIR.Default:
null
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.
Hooks fired · 1
One hook fires while get_available_languages() runs, in this order:
- apply_filters( get_available_languages )filterline 1506 (+28 into the body)
Filters the list of available language codes.
Uses · 2
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 13
- WP_Locale_Switcher::__construct()Constructor.
- WP_REST_Plugins_Controller::create_item()Uploads a plugin and optionally activates it.
- WP_REST_Users_Controller::get_item_schema()Retrieves the user's schema, conforming to JSON Schema.
- edit_user()Edit user settings based on contents of $_POST
- login_footer()Outputs the footer for the login page.
- register_new_user()Handles registering a new user.
- sanitize_option()Sanitizes various option values based on the nature of the option.
- signup_get_available_languages()Retrieves languages available during the site/user sign-up process.
- upgrade_400()Execute changes made in WordPress 4.0.0.
- wp_download_language_pack()Download a language pack.
- wp_install_language_form()Output the select form for the language selection on the installation screen.
- wp_update_plugins()Checks for available updates to plugins based on the latest versions hosted on WordPress.org.
Show all 13
- wp_update_themes()Checks for available updates to themes based on the latest versions hosted on WordPress.org.
Source
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 );}History
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.5.0
The initial file list is now cached and also takes into account *.l10n.php files.from the docblock
4.7.0
The results are now filterable with the 'get_available_languages' filter.from the docblock
3.0.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/l10n.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.