wp_get_available_translations(): array
- Since
- 4.0.0
- Source
wp-admin/includes/translation-install.php:167
Return value
array- Array of translations keyed by the language code, each an associative array of data. If the API response results in an error, an empty array will be returned.
...$0array@type string $language Language code.$versionstringWordPress version.$updatedstringDate the translation was last updated, in MySQL datetime format.$english_namestringEnglish name of the language.$native_namestringNative name of the language.$packagestringURL to download the translation package.$isostring[]Array of ISO language codes.$stringsarrayArray of translated strings used in the installation process.
Performance profile
How much work a call to wp_get_available_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
- Expensive
- Scaling
- Scales with input
- Instructions
- 10–38
- Plugin surface
- None
- Called by
- 2
Reaches an outbound HTTP request via wp_remote_post().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.4, depending on the branch taken. The body compiles to 44.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- transienttransient
get_site_transient()called directly - hookthird-party callbacks
apply_filters()one call below wp_get_available_translations() - cacheobject cache
wp_cache_get()one call below wp_get_available_translations() - optionnetwork option
get_site_option()one call below wp_get_available_translations() - httpoutbound HTTP request
wp_remote_post()one call below wp_get_available_translations()
Further down the call graph this can also reach serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_available_translations() can have, taken from its control-flow graph on PHP 8.4.
| When | Instructions | Calls it makes |
|---|---|---|
!wp_installing() && $translations !== false | 10 | wp_installing(), get_site_transient() |
wp_installing() | 16–25 | wp_installing(), wp_get_wp_version(), version(), is_wp_error() |
!wp_installing() && $translations === false | 22–31 | wp_installing(), get_site_transient(), wp_get_wp_version(), version(), is_wp_error() |
wp_installing() && !is_wp_error() && !empty($api) && !defined('WP_INSTALLING') | 31–32 | wp_installing(), wp_get_wp_version(), version(), is_wp_error(), set_site_transient() |
!wp_installing() && $translations === false && !is_wp_error() && !empty($api) && !defined('WP_INSTALLING') | 37–38 | wp_installing(), get_site_transient(), wp_get_wp_version(), version(), is_wp_error(), set_site_transient() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3 and 8.4: 44 instructions, 10–38 executed per call, 7 branches. The work does not change between versions.
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 · 6
- wp_installing()Checks or sets whether WordPress is in "installation" mode.
- get_site_transient()Retrieves the value of a site transient.
- translations_api()Retrieve translations from WordPress Translation API.
- wp_get_wp_version()Returns the current WordPress version.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- set_site_transient()Sets/updates the value of a site transient.
Used by · 2
- wp_download_language_pack()Download a language pack.
- wp_dropdown_languages()Displays or returns a Language selector.
Source code
function wp_get_available_translations() { if ( ! wp_installing() ) { $translations = get_site_transient( 'available_translations' ); if ( false !== $translations ) { return $translations; } } $api = translations_api( 'core', array( 'version' => wp_get_wp_version() ) ); if ( is_wp_error( $api ) || empty( $api['translations'] ) ) { return array(); } $translations = array(); // Key the array with the language code. foreach ( $api['translations'] as $translation ) { $translations[ $translation['language'] ] = $translation; } if ( ! defined( 'WP_INSTALLING' ) ) { set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS ); } return $translations;}Changelog
Introduced in 4.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.0.4 tag, from
src/wp-admin/includes/translation-install.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.