wppaste
WordPress

_load_textdomain_just_in_time( string $domain ): bool

Since
4.6.0
Source
wp-includes/l10n.php:1423
Loads plugin and theme text domains just-in-time.

Description

When a textdomain is encountered for the first time, we try to load the translation file from wp-content/languages, removing the need to call load_plugin_textdomain() or load_theme_textdomain().

Compatibility

WordPress
since 4.6.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

$domainstring
Text domain. Unique identifier for retrieving translated strings.

Return value

bool
True when the textdomain is successfully loaded, false otherwise.

Performance profile

How much work a call to _load_textdomain_just_in_time() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
8–72

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place 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 _load_textdomain_just_in_time()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 6 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost _load_textdomain_just_in_time() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always8–10none
$domain !== "default" && !isset($l10n_unloaded[$domain]) && !->has()14->has()
$domain !== "default" && !isset($l10n_unloaded[$domain]) && ->has()23->has(), determine_locale(), ->get()
$domain !== "default" && !isset($l10n_unloaded[$domain]) && ->has() && doing_action()50–53->has(), determine_locale(), ->get(), doing_action(), get_template_directory(), trailingslashit(), get_stylesheet_directory(), trailingslashit(), load_textdomain()
$domain !== "default" && !isset($l10n_unloaded[$domain]) && ->has() && !doing_action() && did_action()54–57->has(), determine_locale(), ->get(), doing_action(), did_action(), get_template_directory(), trailingslashit(), get_stylesheet_directory(), trailingslashit(), load_textdomain()
$domain !== "default" && !isset($l10n_unloaded[$domain]) && ->has() && !doing_action() && !did_action()69–72->has(), determine_locale(), ->get(), doing_action(), did_action(), __(), sprintf(), _doing_it_wrong(), get_template_directory(), trailingslashit(), get_stylesheet_directory(), trailingslashit(), load_textdomain()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev798–728
8.5798–728
8.4798–7286 fewer instructions than PHP 8.3
8.3858–788
8.2858–788
8.1858–788
7.4858–788

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 · 10

Used by · 1

Source code

function _load_textdomain_just_in_time( $domain ) {	/** @var WP_Textdomain_Registry $wp_textdomain_registry */	global $l10n_unloaded, $wp_textdomain_registry; 	$l10n_unloaded = (array) $l10n_unloaded; 	// Short-circuit if domain is 'default' which is reserved for core.	if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) {		return false;	} 	if ( ! $wp_textdomain_registry->has( $domain ) ) {		return false;	} 	$locale = determine_locale();	$path   = $wp_textdomain_registry->get( $domain, $locale );	if ( ! $path ) {		return false;	} 	if ( ! doing_action( 'after_setup_theme' ) && ! did_action( 'after_setup_theme' ) ) {		_doing_it_wrong(			__FUNCTION__,			sprintf(				/* translators: 1: The text domain. 2: 'init'. */				__( 'Translation loading for the %1$s domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the %2$s action or later.' ),				'<code>' . $domain . '</code>',				'<code>init</code>'			),			'6.7.0'		);	} 	// Themes with their language directory outside of WP_LANG_DIR have a different file name.	$template_directory   = trailingslashit( get_template_directory() );	$stylesheet_directory = trailingslashit( get_stylesheet_directory() );	if ( str_starts_with( $path, $template_directory ) || str_starts_with( $path, $stylesheet_directory ) ) {		$mofile = "{$path}{$locale}.mo";	} else {		$mofile = "{$path}{$domain}-{$locale}.mo";	} 	return load_textdomain( $domain, $mofile, $locale );}

Changelog

Introduced in 4.6.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-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.