From fab6a5acac83a55aa9560c27bd623e6d8ebcd1ca Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 4 May 2026 13:16:41 +0530 Subject: [PATCH 1/5] 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; From 02dff13c83e8e07b7736f8fc72aa88b8f66e62b1 Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Thu, 7 May 2026 11:35:00 +0530 Subject: [PATCH 2/5] Script Loader: Simplify inline script tag output by inlining the concatenated source URL --- src/wp-includes/script-loader.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index a97121faa4682..8f2f83f306866 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2231,9 +2231,7 @@ function _print_scripts() { if ( $concat ) { if ( ! empty( $wp_scripts->print_code ) ) { - $inline_code = $wp_scripts->print_code - . sprintf( "\n//# sourceURL=%s", rawurlencode( 'js-inline-concat-' . $concat ) ); - wp_print_inline_script_tag( $inline_code ); + wp_print_inline_script_tag( $wp_scripts->print_code . "\n//# sourceURL=" . rawurlencode( 'js-inline-concat-' . $concat ) ); } $concat = str_split( $concat, 128 ); From 644e5a176f631b4193f972aecf8477a14a1bdb51 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 13 Jul 2026 22:48:42 -0700 Subject: [PATCH 3/5] Add missing global doc tags --- tests/phpunit/tests/dependencies/scripts.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 247bf14728fb9..42109ce564126 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -2275,6 +2275,9 @@ public function test_protocols() { /** * Test script concatenation. + * + * @global WP_Scripts $wp_scripts + * @global string $wp_version */ public function test_script_concatenation() { global $wp_scripts, $wp_version; @@ -4310,6 +4313,9 @@ public function test_source_url_encoding() { /** * @ticket 63887 + * + * @global WP_Scripts $wp_scripts + * @global string $wp_version */ public function test_source_url_with_concat() { global $wp_scripts, $concatenate_scripts, $wp_version; From da158cce01258d618a700b7246e889f41a968d20 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 13 Jul 2026 22:49:56 -0700 Subject: [PATCH 4/5] Indent heredoc now that PHP 7.4 is minimum version --- tests/phpunit/tests/dependencies/scripts.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 42109ce564126..9827690cf412d 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -4334,13 +4334,13 @@ 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; + HTML; $this->assertEqualHTML( $expected, $print_scripts ); } From 3835f31badea9aa7218de8a93f55c6366d75c664 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 13 Jul 2026 22:58:56 -0700 Subject: [PATCH 5/5] Add remaining missing global tag --- tests/phpunit/tests/dependencies/scripts.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 9827690cf412d..bbf301fe424cd 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -4315,6 +4315,7 @@ public function test_source_url_encoding() { * @ticket 63887 * * @global WP_Scripts $wp_scripts + * @global bool $concatenate_scripts * @global string $wp_version */ public function test_source_url_with_concat() {