get_available_languages( string $dir = null ): string[]
- Since
- 3.0.0, 4.7.0, 6.5.0
- Source
wp-includes/l10n.php:1552
Description
The default directory is WP_LANG_DIR.
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$dirstringoptional- A directory to search for language files.
Default WP_LANG_DIR.Default:null
Return value
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.
Performance profile
How much work a call to get_available_languages() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 19–23
- Plugin surface
- 1 hook
- Called by
- 13
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 42.
Third-party callbacks on 'get_available_languages' run inside this call, and their cost is not bounded by anything here.
13 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_available_languages() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 19–23 | ->get_language_files_from_path(), array_unique(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 42 | 19–23 | 7 | |
| 8.5 | 42 | 19–23 | 7 | |
| 8.4 | 42 | 19–23 | 7 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 51 | 19–23 | 7 | |
| 8.2 | 51 | 19–23 | 7 | |
| 8.1 | 51 | 19–23 | 7 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 52 | 19–24 | 7 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while get_available_languages() runs, in this order:
- apply_filters( get_available_languages )filterline 1580 (+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 code
function get_available_languages( $dir = null ) { global $wp_textdomain_registry; $languages = array(); $path = $dir ?? WP_LANG_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 );}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.