Skip to content

Commit 45ae336

Browse files
committed
Include the sourceURL comment when printed by do_item
WP_Scripts uses print_translations() internally with $display == false. In this case, the sourceURL comment is still desirable so include it.
1 parent 1c77555 commit 45ae336

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,16 @@ public function do_item( $handle, $group = false ) {
350350

351351
$translations = $this->print_translations( $handle, false );
352352
if ( $translations ) {
353-
$translations = wp_get_inline_script_tag( $translations, array( 'id' => "{$handle}-js-translations" ) );
353+
/**
354+
* The soucreURL comment is not included by @see WP_Scripts::print_translations()
355+
* when `$display == false` to prevent issues where the script tag contents are used
356+
* by extenders for other purposes, for example concatenated with other script content.
357+
*
358+
* Include the sourceURL comment here as it would be when printed directly.
359+
*/
360+
$source_url = rawurlencode( "{$handle}-js-translations" );
361+
$translations .= "\n//# sourceURL={$source_url}";
362+
$translations = wp_get_inline_script_tag( $translations, array( 'id' => "{$handle}-js-translations" ) );
354363
}
355364

356365
if ( $this->do_concat ) {

0 commit comments

Comments
 (0)