From a16a7b5e15c39966f59f15b42484a89d4fe3ae15 Mon Sep 17 00:00:00 2001
From: Dan Knauss <dan@newlocalmedia.com>
Date: Fri, 8 May 2026 02:45:53 -0600
Subject: [PATCH] Docs: Clarify cache bootstrap and legacy compression flags

---
 src/wp-includes/load.php                     |  3 ++
 src/wp-includes/script-loader.php            | 41 ++++++++++++------
 src/wp-settings.php                          |  6 ++-
 tests/phpunit/tests/dependencies/scripts.php | 38 +++++++++++++++++
 tests/phpunit/tests/dependencies/styles.php  | 44 ++++++++++++++++++++
 5 files changed, 117 insertions(+), 15 deletions(-)

diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php
index 27c58b57dd..f2ba8640b2 100644
--- a/src/wp-includes/load.php
+++ b/src/wp-includes/load.php
@@ -824,6 +824,9 @@ function wp_using_ext_object_cache( $using = null ) {
  *
  * If an object-cache.php file exists in the wp-content directory,
  * it uses that drop-in as an external object cache.
+ * This is separate from the advanced-cache.php drop-in loaded
+ * earlier when WP_CACHE is enabled, though advanced-cache.php may
+ * load object-cache.php before this function runs.
  *
  * @since 3.0.0
  * @access private
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php
index 42d42b3f87..38438118e9 100644
--- a/src/wp-includes/script-loader.php
+++ b/src/wp-includes/script-loader.php
@@ -2,16 +2,24 @@
 /**
  * WordPress scripts and styles default loader.
  *
- * Several constants are used to manage the loading, concatenating and compression of scripts and CSS:
- * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS, and disables compression and concatenation,
- * define('CONCATENATE_SCRIPTS', false); disables compression and concatenation of scripts and CSS,
- * define('COMPRESS_SCRIPTS', false); disables compression of scripts,
- * define('COMPRESS_CSS', false); disables compression of CSS,
- * define('ENFORCE_GZIP', true); forces gzip for compression (default is deflate).
+ * Several constants are used to manage loading and concatenation for scripts
+ * and CSS, plus legacy compression URL flags:
+ * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of
+ * all scripts and CSS, and disables concatenation,
+ * define('CONCATENATE_SCRIPTS', false); disables concatenation of scripts and CSS,
+ * define('COMPRESS_SCRIPTS', false); sets the legacy script loader compression
+ * URL flag to false,
+ * define('COMPRESS_CSS', false); sets the legacy style loader compression URL
+ * flag to false,
+ * define('ENFORCE_GZIP', true); sets the legacy compression URL flag to gzip
+ * when compression is otherwise enabled.
  *
  * The globals $concatenate_scripts, $compress_scripts and $compress_css can be set by plugins
- * to temporarily override the above settings. Also a compression test is run once and the result is saved
- * as option 'can_compress_scripts' (0/1). The test will run again if that option is deleted.
+ * to temporarily override the above settings. The $compress_scripts and
+ * $compress_css globals only determine the `c` query argument on
+ * load-scripts.php and load-styles.php URLs.
+ * The loader endpoints do not perform PHP-based compression based on that
+ * argument.
  *
  * @package WordPress
  */
@@ -2217,11 +2225,13 @@ function print_footer_scripts() {
  * @ignore
  *
  * @global WP_Scripts $wp_scripts
- * @global bool       $compress_scripts
+ * @global bool       $compress_scripts Whether to set the legacy script loader
+ *                                      compression URL flag.
  */
 function _print_scripts() {
 	global $wp_scripts, $compress_scripts;
 
+	// Retain the legacy `c` query argument for compatibility with existing loader URLs.
 	$zip = $compress_scripts ? 1 : 0;
 	if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) {
 		$zip = 'gzip';
@@ -2405,13 +2415,15 @@ function print_late_styles() {
  * @ignore
  * @since 3.3.0
  *
- * @global bool $compress_css
+ * @global bool $compress_css Whether to set the legacy style loader
+ *                            compression URL flag.
  */
 function _print_styles() {
 	global $compress_css;
 
 	$wp_styles = wp_styles();
 
+	// Retain the legacy `c` query argument for compatibility with existing loader URLs.
 	$zip = $compress_css ? 1 : 0;
 	if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) {
 		$zip = 'gzip';
@@ -2450,13 +2462,16 @@ function _print_styles() {
 }
 
 /**
- * Determines the concatenation and compression settings for scripts and styles.
+ * Determines the concatenation settings and legacy compression URL flags for
+ * scripts and styles.
  *
  * @since 2.8.0
  *
  * @global bool $concatenate_scripts
- * @global bool $compress_scripts
- * @global bool $compress_css
+ * @global bool $compress_scripts Whether scripts should use the legacy
+ *                                compression URL flag.
+ * @global bool $compress_css     Whether styles should use the legacy
+ *                                compression URL flag.
  */
 function script_concat_settings() {
 	global $concatenate_scripts, $compress_scripts, $compress_css;
diff --git a/src/wp-settings.php b/src/wp-settings.php
index dab1d8fd4c..bb2aaf7d2b 100644
--- a/src/wp-settings.php
+++ b/src/wp-settings.php
@@ -96,7 +96,8 @@ wp_debug_mode();
  *                                    Default true.
  */
 if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) {
-	// For an advanced caching plugin to use. Uses a static drop-in because you would only want one.
+	// Load the advanced cache drop-in early in bootstrap. This is separate from
+	// the object cache drop-in loaded later by wp_start_object_cache().
 	include WP_CONTENT_DIR . '/advanced-cache.php';
 
 	// Re-initialize any hooks added manually by advanced-cache.php.
@@ -147,7 +148,8 @@ if ( ! isset( $GLOBALS['table_prefix'] ) ) {
 // Set the database table prefix and the format specifiers for database table columns.
 wp_set_wpdb_vars();
 
-// Start the WordPress object cache, or an external object cache if the drop-in is present.
+// Start the WordPress object cache, loading the object-cache.php drop-in if
+// present. This is independent of WP_CACHE and advanced-cache.php.
 wp_start_object_cache();
 
 // Attach the default filters.
diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php
index 5f1c30fe4c..c9e73747f4 100644
--- a/tests/phpunit/tests/dependencies/scripts.php
+++ b/tests/phpunit/tests/dependencies/scripts.php
@@ -2063,6 +2063,44 @@ HTML;
 		$this->assertSame( $expected, $print_scripts );
 	}
 
+	/**
+	 * Tests that concatenated script URLs retain the legacy compression query argument.
+	 *
+	 * @ticket 63017
+	 *
+	 * @covers ::_print_scripts
+	 */
+	public function test_script_concatenation_retains_legacy_compression_query_arg() {
+		global $wp_scripts, $compress_scripts, $wp_version;
+
+		$had_compress_scripts = array_key_exists( 'compress_scripts', $GLOBALS );
+		$old_compress_scripts = $had_compress_scripts ? $compress_scripts : null;
+
+		try {
+			$compress_scripts = true;
+
+			$wp_scripts->do_concat    = true;
+			$wp_scripts->default_dirs = array( $this->default_scripts_dir );
+
+			wp_enqueue_script( 'one', $this->default_scripts_dir . 'one.js' );
+			wp_enqueue_script( 'two', $this->default_scripts_dir . 'two.js' );
+
+			wp_print_scripts();
+			$print_scripts = get_echo( '_print_scripts' );
+
+			$expected = "<script src='/wp-admin/load-scripts.php?c=1&amp;load%5Bchunk_0%5D=one,two"
+				. "&amp;ver={$wp_version}'></script>\n";
+
+			$this->assertSame( $expected, $print_scripts );
+		} finally {
+			if ( $had_compress_scripts ) {
+				$compress_scripts = $old_compress_scripts;
+			} else {
+				unset( $GLOBALS['compress_scripts'] );
+			}
+		}
+	}
+
 	/**
 	 * Testing `wp_script_add_data` with the data key.
 	 *
diff --git a/tests/phpunit/tests/dependencies/styles.php b/tests/phpunit/tests/dependencies/styles.php
index de6fefb94b..800d98c622 100644
--- a/tests/phpunit/tests/dependencies/styles.php
+++ b/tests/phpunit/tests/dependencies/styles.php
@@ -888,6 +888,50 @@ HTML;
 		$this->assertEqualHTML( $expected, $printed );
 	}
 
+	/**
+	 * Tests that concatenated style URLs retain the legacy compression query argument.
+	 *
+	 * @ticket 63017
+	 *
+	 * @covers ::_print_styles
+	 */
+	public function test_style_concatenation_retains_legacy_compression_query_arg() {
+		global $wp_styles, $compress_css, $wp_version;
+
+		$had_compress_css = array_key_exists( 'compress_css', $GLOBALS );
+		$old_compress_css = $had_compress_css ? $compress_css : null;
+
+		try {
+			$compress_css = true;
+
+			$wp_styles->do_concat    = true;
+			$wp_styles->default_dirs = array( '/wp-admin/' );
+
+			wp_enqueue_style( 'one', '/wp-admin/one.css' );
+			wp_enqueue_style( 'two', '/wp-admin/two.css' );
+
+			wp_print_styles();
+			$printed = get_echo( '_print_styles' );
+
+			$expected = <<<HTML
+<link
+	rel="stylesheet"
+	href="/wp-admin/load-styles.php?c=1&dir=ltr&load%5Bchunk_0%5D=one,two&ver={$wp_version}"
+	media="all"
+>
+
+HTML;
+
+			$this->assertEqualHTML( $expected, $printed );
+		} finally {
+			if ( $had_compress_css ) {
+				$compress_css = $old_compress_css;
+			} else {
+				unset( $GLOBALS['compress_css'] );
+			}
+		}
+	}
+
 	/**
 	 * Tests that WP_Styles emits a _doing_it_wrong() notice for missing dependencies.
 	 *
-- 
2.50.1 (Apple Git-155)

