wppaste
WordPress

wp_get_available_translations(): array

Since
4.0.0
Source
wp-admin/includes/translation-install.php:167
Get available translations from the WordPress.org API.

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.
    • $versionstring

      WordPress version.
    • $updatedstring

      Date the translation was last updated, in MySQL datetime format.
    • $english_namestring

      English name of the language.
    • $native_namestring

      Native name of the language.
    • $packagestring

      URL to download the translation package.
    • $isostring[]

      Array of ISO language codes.
    • $stringsarray

      Array 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

Reaches an outbound HTTP request via wp_remote_post().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
10–38

Executed per call on PHP 8.4, depending on the branch taken. The body compiles to 44.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

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

What it touches

  • transienttransientget_site_transient()called directly
  • hookthird-party callbacksapply_filters()one call below wp_get_available_translations()
  • cacheobject cachewp_cache_get()one call below wp_get_available_translations()
  • optionnetwork optionget_site_option()one call below wp_get_available_translations()
  • httpoutbound HTTP requestwp_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.

WhenInstructionsCalls it makes
!wp_installing() && $translations !== false10wp_installing()get_site_transient()
wp_installing()16–25wp_installing()wp_get_wp_version()version()is_wp_error()
!wp_installing() && $translations === false22–31wp_installing()get_site_transient()wp_get_wp_version()version()is_wp_error()
wp_installing() && !is_wp_error() && !empty($api) && !defined('WP_INSTALLING')31–32wp_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–38wp_installing()get_site_transient()wp_get_wp_version()version()is_wp_error()set_site_transient()

Across PHP versions

PHPCompiledExecutedBranchesNotes
7.44410–387Compiles to the same instructions
8.14410–387Compiles to the same instructions
8.24410–387Compiles to the same instructions
8.34410–387Compiles to the same instructions
8.44410–387Compiles to the same instructions

Oldest PHP that compiles this body: 7.4. An instruction is not a fixed amount of time, so a version with the same count is not necessarily the same speed; what the count rules out is a difference in the work itself.

Uses · 6

Used by · 2

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.

  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.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.