load_script_translations( string|false $file, string $handle, string $domain ): string|false
- Since
- 5.0.2
- Source
wp-includes/l10n.php:1358
Compatibility
- WordPress
- since 5.0.2
- 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
$filestring|false- Path to the translation file to load. False if there isn't one.
$handlestring- Name of the script to register a translation domain to.
$domainstring- The text domain.
Return value
string|false- The JSON-encoded translated strings for the given script handle and text domain.
False if there are none.
Performance profile
How much work a call to load_script_translations() 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
- Constant
- Instructions
- 14–37
- Plugin surface
- 3 hooks
- Called by
- 1
Reads or writes the filesystem via file_get_contents().
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 39.
Third-party callbacks on 'pre_load_script_translations', 'load_script_translation_file', 'load_script_translations' 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 - filesystemfilesystem access
file_get_contents()called directly
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 load_script_translations() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$translations !== null | 14 | apply_filters() |
$translations === null | 22 | apply_filters(), apply_filters() |
$translations === null && !is_readable() | 26 | apply_filters(), apply_filters(), is_readable() |
$translations === null && is_readable() | 37 | apply_filters(), apply_filters(), is_readable(), file_get_contents(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 39 instructions, 14–37 executed per call, 3 branches. The work does not change between versions.
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 · 3
3 hooks fire while load_script_translations() runs, in this order:
- apply_filters( pre_load_script_translations )filterline 1371 (+13 into the body)
Pre-filters script translations for the given file, script handle and text domain.
- apply_filters( load_script_translation_file )filterline 1386 (+28 into the body)
Filters the file path for loading script translations for the given script handle and text domain.
- apply_filters( load_script_translations )filterline 1404 (+46 into the body)
Filters script translations for the given file, script handle and text domain.
Uses · 1
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 1
- _load_script_textdomain_from_src()Resolves and loads the translation JSON file for a given script or script module source URL.
Source code
function load_script_translations( $file, $handle, $domain ) { /** * Pre-filters script translations for the given file, script handle and text domain. * * Returning a non-null value allows to override the default logic, effectively short-circuiting the function. * * @since 5.0.2 * * @param string|false|null $translations JSON-encoded translation data. Default null. * @param string|false $file Path to the translation file to load. False if there isn't one. * @param string $handle Name of the script to register a translation domain to. * @param string $domain The text domain. */ $translations = apply_filters( 'pre_load_script_translations', null, $file, $handle, $domain ); if ( null !== $translations ) { return $translations; } /** * Filters the file path for loading script translations for the given script handle and text domain. * * @since 5.0.2 * * @param string|false $file Path to the translation file to load. False if there isn't one. * @param string $handle Name of the script to register a translation domain to. * @param string $domain The text domain. */ $file = apply_filters( 'load_script_translation_file', $file, $handle, $domain ); if ( ! $file || ! is_readable( $file ) ) { return false; } $translations = file_get_contents( $file ); /** * Filters script translations for the given file, script handle and text domain. * * @since 5.0.2 * * @param string $translations JSON-encoded translation data. * @param string $file Path to the translation file that was loaded. * @param string $handle Name of the script to register a translation domain to. * @param string $domain The text domain. */ return apply_filters( 'load_script_translations', $translations, $file, $handle, $domain );}Changelog
Introduced in 5.0.2. 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.0.4 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.