WP_Theme::translate_header( string $header, string|array $value ): string|array
- Since
- 3.4.0
- Source
wp-includes/class-wp-theme.php:1050
Compatibility
- WordPress
- since 3.4.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
$headerstring- Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
$valuestring|array- Value to translate. An array for Tags header, string otherwise.
Return value
string|array- Translated value. An array for Tags header, string otherwise.
Performance profile
How much work a call to WP_Theme::translate_header() 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
- 6–114
- Plugin surface
- None
- Called by
- 2
Reads stored settings via get_site_transient(), cached per request but not free on a cold cache.
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 155.
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
- hookthird-party callbacks
apply_filters()one call below WP_Theme::translate_header() - transienttransient
get_site_transient()one call below WP_Theme::translate_header()
Further down the call graph this can also reach cache, option, http, query and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme::translate_header() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–10 | none |
!empty($value) | 10–20 | function_exists() |
| always | 12–18 | ->get(), translate() |
!empty($value) && function_exists() && !isset($tags_list) | 108–114 | function_exists(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), _x(), _x(), __(), __(), __(), __(), __(), __(), get_theme_feature_list() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 155 | 6–114 | 13 | |
| 8.5 | 155 | 6–114 | 13 | |
| 8.4 | 155 | 6–114 | 13 | |
| 8.3 | 155 | 6–114 | 13 | |
| 8.2 | 155 | 6–114 | 13 | 1 more instruction than PHP 8.1 |
| 8.1 | 154 | 6–114 | 13 | |
| 7.4 | 154 | 6–114 | 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 · 5
- translate()Retrieves the translation of $text.
- __()Retrieves the translation of $text.
- _x()Retrieves translated string with gettext context.
- get_theme_feature_list()Retrieves list of WordPress theme features (aka theme tags).
- WP_Theme::get()Gets a raw, unformatted theme header.
Used by · 2
- WP_Theme::display()Gets a theme header, formatted and translated for display.
- WP_Theme::get_post_templates()Returns the theme's post templates.
Source code
private function translate_header( $header, $value ) { switch ( $header ) { case 'Name': // Cached for sorting reasons. if ( isset( $this->name_translated ) ) { return $this->name_translated; } // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain $this->name_translated = translate( $value, $this->get( 'TextDomain' ) ); return $this->name_translated; case 'Tags': if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) { return $value; } static $tags_list; if ( ! isset( $tags_list ) ) { $tags_list = array( // As of 4.6, deprecated tags which are only used to provide translation for older themes. 'black' => __( 'Black' ), 'blue' => __( 'Blue' ), 'brown' => __( 'Brown' ), 'gray' => __( 'Gray' ), 'green' => __( 'Green' ), 'orange' => __( 'Orange' ), 'pink' => __( 'Pink' ), 'purple' => __( 'Purple' ), 'red' => __( 'Red' ), 'silver' => __( 'Silver' ), 'tan' => __( 'Tan' ), 'white' => __( 'White' ), 'yellow' => __( 'Yellow' ), 'dark' => _x( 'Dark', 'color scheme' ), 'light' => _x( 'Light', 'color scheme' ), 'fixed-layout' => __( 'Fixed Layout' ), 'fluid-layout' => __( 'Fluid Layout' ), 'responsive-layout' => __( 'Responsive Layout' ), 'blavatar' => __( 'Blavatar' ), 'photoblogging' => __( 'Photoblogging' ), 'seasonal' => __( 'Seasonal' ), ); $feature_list = get_theme_feature_list( false ); // No API. foreach ( $feature_list as $tags ) { $tags_list += $tags; } } foreach ( $value as &$tag ) { if ( isset( $tags_list[ $tag ] ) ) { $tag = $tags_list[ $tag ]; } elseif ( isset( self::$tag_map[ $tag ] ) ) { $tag = $tags_list[ self::$tag_map[ $tag ] ]; } } return $value; default: // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain $value = translate( $value, $this->get( 'TextDomain' ) ); } return $value; }Changelog
Introduced in 3.4.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.9.7 tag, from
src/wp-includes/class-wp-theme.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.