Skip to content

Commit 1c77555

Browse files
committed
Prevent adding sourceURL to translation script if not printed
It's unclear how the script tag contents may be used by extenders. Avoid printing the sourceURL if the contents are not immediately printed. See https://github.com/WordPress/wordpress-develop/blob/81e3dbeba63838a13b137c6308548e35a616f3b6/src/wp-includes/script-loader.php#L3015.
1 parent 81e3dbe commit 1c77555

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/wp-includes/class-wp-scripts.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,18 +722,17 @@ public function print_translations( $handle, $display = true ) {
722722
return false;
723723
}
724724

725-
$source_url = rawurlencode( "{$handle}-js-translations" );
726-
727725
$output = <<<JS
728726
( function( domain, translations ) {
729727
var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
730728
localeData[""].domain = domain;
731729
wp.i18n.setLocaleData( localeData, domain );
732730
} )( "{$domain}", {$json_translations} );
733-
//# sourceURL={$source_url}
734731
JS;
735732

736733
if ( $display ) {
734+
$source_url = rawurlencode( "{$handle}-js-translations" );
735+
$output .= "\n//# sourceURL={$source_url}";
737736
wp_print_inline_script_tag( $output, array( 'id' => "{$handle}-js-translations" ) );
738737
}
739738

0 commit comments

Comments
 (0)