_WP_Editors::wp_mce_translation( string $mce_locale = '', bool $json_only = false ): string
- Since
- 3.9.0
- Source
wp-includes/class-wp-editor.php:1466
Compatibility
- WordPress
- since 3.9.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
$mce_localestringoptional- The locale used for the editor.Default:
'' $json_onlybooloptional- Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone(). Default false.Default:
false
Return value
string- Translation object, JSON encoded.
Performance profile
How much work a call to _WP_Editors::wp_mce_translation() 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
- 24–45
- Plugin surface
- 1 hook
- 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 71.
Third-party callbacks on 'wp_mce_translation' 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 option, cache, serialize, query 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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _WP_Editors::wp_mce_translation() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 24–28 | ::get_translation(), apply_filters(), is_rtl(), wp_json_encode() |
| always | 27–31 | ::get_mce_locale(), ::get_translation(), apply_filters(), is_rtl(), wp_json_encode() |
| always | 38–42 | ::get_translation(), apply_filters(), is_rtl(), ::get_baseurl(), wp_json_encode() |
| always | 41–45 | ::get_mce_locale(), ::get_translation(), apply_filters(), is_rtl(), ::get_baseurl(), wp_json_encode() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 71 | 24–45 | 10 | |
| 8.5 | 71 | 24–45 | 10 | |
| 8.4 | 71 | 24–45 | 10 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 74 | 24–45 | 10 | |
| 8.2 | 74 | 24–45 | 10 | |
| 8.1 | 74 | 24–45 | 10 | |
| 7.4 | 74 | 24–45 | 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.
Hooks and filters fired · 1
One hook fires while _WP_Editors::wp_mce_translation() runs, in this order:
- apply_filters( wp_mce_translation )filterline 1487 (+21 into the body)
Filters translated strings prepared for TinyMCE.
Uses · 7
- apply_filters()Calls the callback functions that have been added to a filter hook.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- is_rtl()Determines whether the current locale is right-to-left (RTL).
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- _WP_Editors::get_mce_locale()Returns the TinyMCE locale.
- _WP_Editors::get_translation()
- _WP_Editors::get_baseurl()Returns the TinyMCE base URL.
Used by · 1
- _WP_Editors::print_tinymce_scripts()Print (output) the main TinyMCE scripts.
Source code
public static function wp_mce_translation( $mce_locale = '', $json_only = false ) { if ( ! $mce_locale ) { $mce_locale = self::get_mce_locale(); } $mce_translation = self::get_translation(); foreach ( $mce_translation as $name => $value ) { if ( is_array( $value ) ) { $mce_translation[ $name ] = $value[0]; } } /** * Filters translated strings prepared for TinyMCE. * * @since 3.9.0 * * @param array $mce_translation Key/value pairs of strings. * @param string $mce_locale Locale. */ $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale ); foreach ( $mce_translation as $key => $value ) { // Remove strings that are not translated. if ( $key === $value ) { unset( $mce_translation[ $key ] ); continue; } if ( str_contains( $value, '&' ) ) { $mce_translation[ $key ] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' ); } } // Set direction. if ( is_rtl() ) { $mce_translation['_dir'] = 'rtl'; } if ( $json_only ) { return wp_json_encode( $mce_translation ); } $baseurl = self::get_baseurl(); return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" . "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n"; }Changelog
Introduced in 3.9.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 6.7.7 tag, from
src/wp-includes/class-wp-editor.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.