WP_Textdomain_Registry::get_path_from_lang_dir( string $domain, string $locale ): string|false
- Since
- 6.1.0
- Source
wp-includes/class-wp-textdomain-registry.php:313
Description
Checks the plugins and themes language directories as well as any custom directory set via load_plugin_textdomain() or load_theme_textdomain().
Compatibility
- WordPress
- since 6.1.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.
$localestring- Locale.
Return value
string|false- Language directory path or false if there is none available.
Performance profile
How much work a call to WP_Textdomain_Registry::get_path_from_lang_dir() 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
- Light
- Scaling
- Scales with input
- Instructions
- 16–71
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
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 85.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
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_Textdomain_Registry::get_path_from_lang_dir() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 16–20 | ->get_paths_for_domain(), ->set() |
isset($domain) | 26–27 | ->get_paths_for_domain(), rtrim(), ->set() |
!$locations && !$files && $file_path === false | 50–64 | ->get_paths_for_domain(), ->get_language_files_from_path(), rtrim(), ->set() |
!$locations && !$files && $file_path === false && isset($domain) | 60–71 | ->get_paths_for_domain(), ->get_language_files_from_path(), rtrim(), rtrim(), ->set() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 85 | 16–71 | 10 | |
| 8.5 | 85 | 16–71 | 10 | |
| 8.4 | 85 | 16–71 | 10 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 94 | 16–80 | 10 | |
| 8.2 | 94 | 16–80 | 10 | |
| 8.1 | 94 | 16–80 | 10 | |
| 7.4 | 94 | 16–80 | 10 |
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 · 4
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- WP_Textdomain_Registry::get_paths_for_domain()Returns possible language directory paths for a given text domain.
- WP_Textdomain_Registry::get_language_files_from_path()Retrieves translation files from the specified path.
- WP_Textdomain_Registry::set()Sets the language directory path for a specific domain and locale.
Used by · 1
- WP_Textdomain_Registry::get()Returns the languages directory path for a specific domain and locale.
Source code
private function get_path_from_lang_dir( $domain, $locale ) { $locations = $this->get_paths_for_domain( $domain ); $found_location = false; foreach ( $locations as $location ) { $files = $this->get_language_files_from_path( $location ); $mo_path = "$location/$domain-$locale.mo"; $php_path = "$location/$domain-$locale.l10n.php"; foreach ( $files as $file_path ) { if ( ! in_array( $domain, $this->domains_with_translations, true ) && str_starts_with( str_replace( "$location/", '', $file_path ), "$domain-" ) ) { $this->domains_with_translations[] = $domain; } if ( $file_path === $mo_path || $file_path === $php_path ) { $found_location = rtrim( $location, '/' ) . '/'; break 2; } } } if ( $found_location ) { $this->set( $domain, $locale, $found_location ); return $found_location; } /* * If no path is found for the given locale and a custom path has been set * using load_plugin_textdomain/load_theme_textdomain, use that one. */ if ( isset( $this->custom_paths[ $domain ] ) ) { $fallback_location = rtrim( $this->custom_paths[ $domain ], '/' ) . '/'; $this->set( $domain, $locale, $fallback_location ); return $fallback_location; } $this->set( $domain, $locale, false ); return false; }Changelog
Introduced in 6.1.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.1.0 tag, from
src/wp-includes/class-wp-textdomain-registry.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.