load_script_textdomain( string $handle, string $domain = 'default', string $path = '' ): string|false
- Since
- 5.0.0, 5.0.2, 5.1.0
- Source
wp-includes/l10n.php:1143
Compatibility
- WordPress
- since 5.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
$handlestring- Name of the script to register a translation domain to.
$domainstringoptional- Text domain. Default 'default'.Default:
'default' $pathstringoptional- The full file path to the directory containing translation files.Default:
''
Return value
string|false- The translated strings in JSON encoding on success, false if the script textdomain could not be loaded.
Performance profile
How much work a call to load_script_textdomain() 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
- Scaling
- Constant
- Instructions
- 90–166
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 259.
Third-party callbacks on 'load_script_textdomain_relative_path' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
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 · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost load_script_textdomain() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
isset($handle) && $domain !== "default" && isset($content_url) && isset($plugins_url) && $relative === false | 90–117 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), apply_filters(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && isset($plugins_url) && isset($site_url) && $relative === false | 95–128 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), trailingslashit(), apply_filters(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && $relative === false | 102–129 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), explode(), array_slice(), apply_filters(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && isset($plugins_url) && $relative !== false | 106–137 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), apply_filters(), str_ends_with(), md5(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && isset($plugins_url) && isset($site_url) && $relative !== false | 111–148 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), trailingslashit(), apply_filters(), str_ends_with(), md5(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && isset($plugins_url) && $relative !== false | 111–146 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), apply_filters(), str_ends_with(), md5(), load_script_translations(), load_script_translations() |
isset($handle) && $domain !== "default" && $relative === false | 112–132 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), explode(), explode(), array_slice(), array_slice(), apply_filters(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && isset($plugins_url) && isset($site_url) && $relative !== false | 116–157 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), trailingslashit(), apply_filters(), str_ends_with(), md5(), load_script_translations(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && $relative !== false | 118–149 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), explode(), array_slice(), apply_filters(), str_ends_with(), md5(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && isset($plugins_url) && $relative !== false | 120–151 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), apply_filters(), str_ends_with(), md5(), load_script_translations(), load_script_translations(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && $relative !== false | 123–158 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), explode(), array_slice(), apply_filters(), str_ends_with(), md5(), load_script_translations(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && isset($plugins_url) && isset($site_url) && $relative !== false | 125–162 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), trailingslashit(), apply_filters(), str_ends_with(), md5(), load_script_translations(), load_script_translations(), load_script_translations() |
4 further outcomes, up to 166 instructions
isset($handle) && $domain !== "default" && $relative !== false | 128–152 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), explode(), explode(), array_slice(), array_slice(), apply_filters(), str_ends_with(), md5(), load_script_translations() |
isset($handle) && $domain !== "default" && isset($content_url) && $relative !== false | 132–163 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), explode(), array_slice(), apply_filters(), str_ends_with(), md5(), load_script_translations(), load_script_translations(), load_script_translations() |
isset($handle) && $domain !== "default" && $relative !== false | 133–161 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), explode(), explode(), array_slice(), array_slice(), apply_filters(), str_ends_with(), md5(), load_script_translations(), load_script_translations() |
isset($handle) && $domain !== "default" && $relative !== false | 142–166 | wp_scripts(), untrailingslashit(), determine_locale(), wp_parse_url(), content_url(), wp_parse_url(), plugins_url(), wp_parse_url(), site_url(), wp_parse_url(), get_theme_root(), explode(), explode(), array_slice(), array_slice(), apply_filters(), str_ends_with(), md5(), load_script_translations(), load_script_translations(), load_script_translations() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 259 | 90–166 | 30 | |
| 8.5 | 259 | 90–166 | 30 | |
| 8.4 | 259 | 90–166 | 30 | 49 fewer instructions than PHP 8.3 |
| 8.3 | 308 | 100–185 | 30 | |
| 8.2 | 308 | 100–185 | 30 | |
| 8.1 | 308 | 100–185 | 30 | 7 fewer instructions than PHP 7.4 |
| 7.4 | 315 | 103–190 | 30 |
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.
Hooks and filters fired · 1
One hook fires while load_script_textdomain() runs, in this order:
- apply_filters( load_script_textdomain_relative_path )filterline 1242 (+99 into the body)
Filters the relative path of scripts used for finding translation files.
Uses · 13
- wp_scripts()Initializes $wp_scripts if it has not been set.
- untrailingslashit()Removes trailing forward slashes and backslashes if they exist.
- determine_locale()Determines the current locale desired for the request.
- load_script_translations()Loads the translation data for the given script handle and text domain.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- wp_parse_url()A wrapper for PHP's parse_url() function that handles consistency in the return values across PHP versions.
- content_url()Retrieves the URL to the content directory.
- plugins_url()Retrieves a URL within the plugins or mu-plugins directory.
- site_url()Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
- get_theme_root()Retrieves path to themes directory.
- trailingslashit()Appends a trailing slash.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Show all 13
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
Used by · 1
- WP_Scripts::print_translations()Prints translations set for a specific handle.
Source code
function load_script_textdomain( $handle, $domain = 'default', $path = '' ) { $wp_scripts = wp_scripts(); if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { return false; } $path = untrailingslashit( $path ); $locale = determine_locale(); // If a path was given and the handle file exists simply return it. $file_base = 'default' === $domain ? $locale : $domain . '-' . $locale; $handle_filename = $file_base . '-' . $handle . '.json'; if ( $path ) { $translations = load_script_translations( $path . '/' . $handle_filename, $handle, $domain ); if ( $translations ) { return $translations; } } $src = $wp_scripts->registered[ $handle ]->src; if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && str_starts_with( $src, $wp_scripts->content_url ) ) ) { $src = $wp_scripts->base_url . $src; } $relative = false; $languages_path = WP_LANG_DIR; $src_url = wp_parse_url( $src ); $content_url = wp_parse_url( content_url() ); $plugins_url = wp_parse_url( plugins_url() ); $site_url = wp_parse_url( site_url() ); $theme_root = get_theme_root(); // If the host is the same or it's a relative URL. if ( ( ! isset( $content_url['path'] ) || str_starts_with( $src_url['path'], $content_url['path'] ) ) && ( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] ) ) { // Make the src relative the specific plugin or theme. if ( isset( $content_url['path'] ) ) { $relative = substr( $src_url['path'], strlen( $content_url['path'] ) ); } else { $relative = $src_url['path']; } $relative = trim( $relative, '/' ); $relative = explode( '/', $relative ); /* * Ensure correct languages path when using a custom `WP_PLUGIN_DIR` / `WP_PLUGIN_URL` configuration, * a custom theme root, and/or using Multisite with subdirectories. * See https://core.trac.wordpress.org/ticket/60891 and https://core.trac.wordpress.org/ticket/62016. */ $theme_dir = array_slice( explode( '/', $theme_root ), -1 ); $dirname = $theme_dir[0] === $relative[0] ? 'themes' : 'plugins'; $languages_path = WP_LANG_DIR . '/' . $dirname; $relative = array_slice( $relative, 2 ); // Remove plugins/<plugin name> or themes/<theme name>. $relative = implode( '/', $relative ); } elseif ( ( ! isset( $plugins_url['path'] ) || str_starts_with( $src_url['path'], $plugins_url['path'] ) ) && ( ! isset( $src_url['host'] ) || ! isset( $plugins_url['host'] ) || $src_url['host'] === $plugins_url['host'] ) ) { // Make the src relative the specific plugin. if ( isset( $plugins_url['path'] ) ) { $relative = substr( $src_url['path'], strlen( $plugins_url['path'] ) ); } else { $relative = $src_url['path']; } $relative = trim( $relative, '/' ); $relative = explode( '/', $relative ); $languages_path = WP_LANG_DIR . '/plugins'; $relative = array_slice( $relative, 1 ); // Remove <plugin name>.Changelog
Introduced in 5.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$domain parameter was made optional.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.