wp_get_installed_translations( string $type ): array
- Since
- 3.7.0
- Source
wp-includes/l10n.php:1522
Description
Looks in the wp-content/languages directory for translations of plugins or themes.
Compatibility
- WordPress
- since 3.7.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
$typestring- What to search for. Accepts 'plugins', 'themes', 'core'.
Return value
array- Array of language data.
Performance profile
How much work a call to wp_get_installed_translations() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 9–28
- Plugin surface
- None
- Called by
- 5
Reads or writes the filesystem via is_dir().
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 90.
Nothing here hands control to plugin code.
5 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- filesystemfilesystem access
is_dir()called directly
Further down the call graph this can also reach hook. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_installed_translations() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$type !== "themes" && $type !== "plugins" && $type !== "core" | 9 | none |
!is_dir() | 14–19 | is_dir() |
is_dir() | 19–28 | is_dir(), ->get_language_files_from_path() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 90 | 9–28 | 13 | |
| 8.5 | 90 | 9–28 | 13 | |
| 8.4 | 90 | 9–28 | 13 | |
| 8.3 | 90 | 9–28 | 13 | |
| 8.2 | 90 | 9–28 | 13 | |
| 8.1 | 90 | 9–28 | 13 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 92 | 9–29 | 13 |
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.
Uses · 3
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- wp_get_pomo_file_data()Extracts headers from a PO file.
- wp_get_l10n_php_file_data()Extracts headers from a PHP translation file.
Used by · 5
- delete_plugins()Removes directory and files of a plugin for a list of plugins.
- delete_theme()Removes a theme.
- wp_update_plugins()Checks for available updates to plugins based on the latest versions hosted on WordPress.org.
- wp_update_themes()Checks for available updates to themes based on the latest versions hosted on WordPress.org.
- wp_version_check()Checks WordPress version against the newest version.
Source code
function wp_get_installed_translations( $type ) { global $wp_textdomain_registry; if ( 'themes' !== $type && 'plugins' !== $type && 'core' !== $type ) { return array(); } $dir = 'core' === $type ? WP_LANG_DIR : WP_LANG_DIR . "/$type"; if ( ! is_dir( $dir ) ) { return array(); } $files = $wp_textdomain_registry->get_language_files_from_path( $dir ); if ( ! $files ) { return array(); } $language_data = array(); foreach ( $files as $file ) { if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?)\.(?:mo|l10n\.php)/', basename( $file ), $match ) ) { continue; } list( , $textdomain, $language ) = $match; if ( '' === $textdomain ) { $textdomain = 'default'; } if ( str_ends_with( $file, '.mo' ) ) { $pofile = substr_replace( $file, '.po', - strlen( '.mo' ) ); if ( ! file_exists( $pofile ) ) { continue; } $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( $pofile ); } else { $pofile = substr_replace( $file, '.po', - strlen( '.l10n.php' ) ); // If both a PO and a PHP file exist, prefer the PO file. if ( file_exists( $pofile ) ) { continue; } $language_data[ $textdomain ][ $language ] = wp_get_l10n_php_file_data( $file ); } } return $language_data;}Changelog
Introduced in 3.7.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 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.