wppaste
WordPress

WP_Theme::translate_header( string $header, string|array $value ): string|array

Since
3.4.0
Source
wp-includes/class-wp-theme.php:1050
Translates a theme header.

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

Reads stored settings via get_site_transient(), cached per request but not free on a cold cache.

Scaling
Scales with input

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

Instructions
6–114

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

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

  • hookthird-party callbacksapply_filters()one call below WP_Theme::translate_header()
  • transienttransientget_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.

WhenInstructionsCalls it makes
always6–10none
!empty($value)10–20function_exists()
always12–18->get(), translate()
!empty($value) && function_exists() && !isset($tags_list)108–114function_exists(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), __(), _x(), _x(), __(), __(), __(), __(), __(), __(), get_theme_feature_list()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1556–11413
8.51556–11413
8.41556–11413
8.31556–11413
8.21556–114131 more instruction than PHP 8.1
8.11546–11413
7.41546–11413

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

Used by · 2

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.

  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 6.8.8 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.