wppaste
WordPress

get_available_languages( string $dir = null ): string[]

Since
3.0.0, 4.7.0, 6.5.0
Source
wp-includes/l10n.php:1552
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.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
19–23

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 42.

Plugin surface
1 hook

Third-party callbacks on 'get_available_languages' run inside this call, and their cost is not bounded by anything here.

Called by
13

13 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
always19–23->get_language_files_from_path(), array_unique(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev4219–237
8.54219–237
8.44219–2379 fewer instructions than PHP 8.3
8.35119–237
8.25119–237
8.15119–2371 fewer instruction than PHP 7.4
7.45219–247

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:

  1. apply_filters( get_available_languages )filterline 1580 (+28 into the body)

    Filters the list of available language codes.

Uses · 2

Used by · 13

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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 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.