From fab6a5acac83a55aa9560c27bd623e6d8ebcd1ca Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 4 May 2026 13:16:41 +0530 Subject: [PATCH] Script Loader: Use wp_print_script_tag() and wp_print_inline_script_tag() in _print_scripts() --- src/wp-includes/script-loader.php | 9 ++++----- tests/phpunit/tests/dependencies/scripts.php | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 42d42b3f8781d..a97121faa4682 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2231,10 +2231,9 @@ function _print_scripts() { if ( $concat ) { if ( ! empty( $wp_scripts->print_code ) ) { - echo "\n\n"; + $inline_code = $wp_scripts->print_code + . sprintf( "\n//# sourceURL=%s", rawurlencode( 'js-inline-concat-' . $concat ) ); + wp_print_inline_script_tag( $inline_code ); } $concat = str_split( $concat, 128 ); @@ -2245,7 +2244,7 @@ function _print_scripts() { } $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version; - echo "\n"; + wp_print_script_tag( array( 'src' => $src ) ); } if ( ! empty( $wp_scripts->print_html ) ) { diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 5f1c30fe4cf47..d214f265ba1e2 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -2058,9 +2058,9 @@ public function test_script_concatenation() { wp_print_scripts(); $print_scripts = get_echo( '_print_scripts' ); - $expected = "\n"; + $expected = "\n"; - $this->assertSame( $expected, $print_scripts ); + $this->assertEqualHTML( $expected, $print_scripts ); } /** @@ -4093,12 +4093,11 @@ public function test_source_url_with_concat() { $print_scripts = get_echo( '_print_scripts' ); $expected = << var one = {"key":"val"};var two = {"key":"val"}; //# sourceURL=js-inline-concat-one%2Ctwo - + HTML;