Ticket #63017: 63017-small-core-clarification.diff
| File 63017-small-core-clarification.diff, 9.3 KB (added by , 6 months ago) |
|---|
-
src/wp-includes/load.php
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 b function wp_using_ext_object_cache( $using = null ) { 824 824 * 825 825 * If an object-cache.php file exists in the wp-content directory, 826 826 * it uses that drop-in as an external object cache. 827 * This is separate from the advanced-cache.php drop-in loaded 828 * earlier when WP_CACHE is enabled, though advanced-cache.php may 829 * load object-cache.php before this function runs. 827 830 * 828 831 * @since 3.0.0 829 832 * @access private -
src/wp-includes/script-loader.php
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 42d42b3f87..38438118e9 100644
a b 2 2 /** 3 3 * WordPress scripts and styles default loader. 4 4 * 5 * Several constants are used to manage the loading, concatenating and compression of scripts and CSS: 6 * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS, and disables compression and concatenation, 7 * define('CONCATENATE_SCRIPTS', false); disables compression and concatenation of scripts and CSS, 8 * define('COMPRESS_SCRIPTS', false); disables compression of scripts, 9 * define('COMPRESS_CSS', false); disables compression of CSS, 10 * define('ENFORCE_GZIP', true); forces gzip for compression (default is deflate). 5 * Several constants are used to manage loading and concatenation for scripts 6 * and CSS, plus legacy compression URL flags: 7 * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of 8 * all scripts and CSS, and disables concatenation, 9 * define('CONCATENATE_SCRIPTS', false); disables concatenation of scripts and CSS, 10 * define('COMPRESS_SCRIPTS', false); sets the legacy script loader compression 11 * URL flag to false, 12 * define('COMPRESS_CSS', false); sets the legacy style loader compression URL 13 * flag to false, 14 * define('ENFORCE_GZIP', true); sets the legacy compression URL flag to gzip 15 * when compression is otherwise enabled. 11 16 * 12 17 * The globals $concatenate_scripts, $compress_scripts and $compress_css can be set by plugins 13 * to temporarily override the above settings. Also a compression test is run once and the result is saved 14 * as option 'can_compress_scripts' (0/1). The test will run again if that option is deleted. 18 * to temporarily override the above settings. The $compress_scripts and 19 * $compress_css globals only determine the `c` query argument on 20 * load-scripts.php and load-styles.php URLs. 21 * The loader endpoints do not perform PHP-based compression based on that 22 * argument. 15 23 * 16 24 * @package WordPress 17 25 */ … … function print_footer_scripts() { 2217 2225 * @ignore 2218 2226 * 2219 2227 * @global WP_Scripts $wp_scripts 2220 * @global bool $compress_scripts 2228 * @global bool $compress_scripts Whether to set the legacy script loader 2229 * compression URL flag. 2221 2230 */ 2222 2231 function _print_scripts() { 2223 2232 global $wp_scripts, $compress_scripts; 2224 2233 2234 // Retain the legacy `c` query argument for compatibility with existing loader URLs. 2225 2235 $zip = $compress_scripts ? 1 : 0; 2226 2236 if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) { 2227 2237 $zip = 'gzip'; … … function print_late_styles() { 2405 2415 * @ignore 2406 2416 * @since 3.3.0 2407 2417 * 2408 * @global bool $compress_css 2418 * @global bool $compress_css Whether to set the legacy style loader 2419 * compression URL flag. 2409 2420 */ 2410 2421 function _print_styles() { 2411 2422 global $compress_css; 2412 2423 2413 2424 $wp_styles = wp_styles(); 2414 2425 2426 // Retain the legacy `c` query argument for compatibility with existing loader URLs. 2415 2427 $zip = $compress_css ? 1 : 0; 2416 2428 if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) { 2417 2429 $zip = 'gzip'; … … function _print_styles() { 2450 2462 } 2451 2463 2452 2464 /** 2453 * Determines the concatenation and compression settings for scripts and styles. 2465 * Determines the concatenation settings and legacy compression URL flags for 2466 * scripts and styles. 2454 2467 * 2455 2468 * @since 2.8.0 2456 2469 * 2457 2470 * @global bool $concatenate_scripts 2458 * @global bool $compress_scripts 2459 * @global bool $compress_css 2471 * @global bool $compress_scripts Whether scripts should use the legacy 2472 * compression URL flag. 2473 * @global bool $compress_css Whether styles should use the legacy 2474 * compression URL flag. 2460 2475 */ 2461 2476 function script_concat_settings() { 2462 2477 global $concatenate_scripts, $compress_scripts, $compress_css; -
src/wp-settings.php
diff --git a/src/wp-settings.php b/src/wp-settings.php index dab1d8fd4c..bb2aaf7d2b 100644
a b wp_debug_mode(); 96 96 * Default true. 97 97 */ 98 98 if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) { 99 // For an advanced caching plugin to use. Uses a static drop-in because you would only want one. 99 // Load the advanced cache drop-in early in bootstrap. This is separate from 100 // the object cache drop-in loaded later by wp_start_object_cache(). 100 101 include WP_CONTENT_DIR . '/advanced-cache.php'; 101 102 102 103 // Re-initialize any hooks added manually by advanced-cache.php. … … if ( ! isset( $GLOBALS['table_prefix'] ) ) { 147 148 // Set the database table prefix and the format specifiers for database table columns. 148 149 wp_set_wpdb_vars(); 149 150 150 // Start the WordPress object cache, or an external object cache if the drop-in is present. 151 // Start the WordPress object cache, loading the object-cache.php drop-in if 152 // present. This is independent of WP_CACHE and advanced-cache.php. 151 153 wp_start_object_cache(); 152 154 153 155 // Attach the default filters. -
tests/phpunit/tests/dependencies/scripts.php
diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 5f1c30fe4c..c9e73747f4 100644
a b HTML; 2063 2063 $this->assertSame( $expected, $print_scripts ); 2064 2064 } 2065 2065 2066 /** 2067 * Tests that concatenated script URLs retain the legacy compression query argument. 2068 * 2069 * @ticket 63017 2070 * 2071 * @covers ::_print_scripts 2072 */ 2073 public function test_script_concatenation_retains_legacy_compression_query_arg() { 2074 global $wp_scripts, $compress_scripts, $wp_version; 2075 2076 $had_compress_scripts = array_key_exists( 'compress_scripts', $GLOBALS ); 2077 $old_compress_scripts = $had_compress_scripts ? $compress_scripts : null; 2078 2079 try { 2080 $compress_scripts = true; 2081 2082 $wp_scripts->do_concat = true; 2083 $wp_scripts->default_dirs = array( $this->default_scripts_dir ); 2084 2085 wp_enqueue_script( 'one', $this->default_scripts_dir . 'one.js' ); 2086 wp_enqueue_script( 'two', $this->default_scripts_dir . 'two.js' ); 2087 2088 wp_print_scripts(); 2089 $print_scripts = get_echo( '_print_scripts' ); 2090 2091 $expected = "<script src='/wp-admin/load-scripts.php?c=1&load%5Bchunk_0%5D=one,two" 2092 . "&ver={$wp_version}'></script>\n"; 2093 2094 $this->assertSame( $expected, $print_scripts ); 2095 } finally { 2096 if ( $had_compress_scripts ) { 2097 $compress_scripts = $old_compress_scripts; 2098 } else { 2099 unset( $GLOBALS['compress_scripts'] ); 2100 } 2101 } 2102 } 2103 2066 2104 /** 2067 2105 * Testing `wp_script_add_data` with the data key. 2068 2106 * -
tests/phpunit/tests/dependencies/styles.php
diff --git a/tests/phpunit/tests/dependencies/styles.php b/tests/phpunit/tests/dependencies/styles.php index de6fefb94b..800d98c622 100644
a b HTML; 888 888 $this->assertEqualHTML( $expected, $printed ); 889 889 } 890 890 891 /** 892 * Tests that concatenated style URLs retain the legacy compression query argument. 893 * 894 * @ticket 63017 895 * 896 * @covers ::_print_styles 897 */ 898 public function test_style_concatenation_retains_legacy_compression_query_arg() { 899 global $wp_styles, $compress_css, $wp_version; 900 901 $had_compress_css = array_key_exists( 'compress_css', $GLOBALS ); 902 $old_compress_css = $had_compress_css ? $compress_css : null; 903 904 try { 905 $compress_css = true; 906 907 $wp_styles->do_concat = true; 908 $wp_styles->default_dirs = array( '/wp-admin/' ); 909 910 wp_enqueue_style( 'one', '/wp-admin/one.css' ); 911 wp_enqueue_style( 'two', '/wp-admin/two.css' ); 912 913 wp_print_styles(); 914 $printed = get_echo( '_print_styles' ); 915 916 $expected = <<<HTML 917 <link 918 rel="stylesheet" 919 href="/wp-admin/load-styles.php?c=1&dir=ltr&load%5Bchunk_0%5D=one,two&ver={$wp_version}" 920 media="all" 921 > 922 923 HTML; 924 925 $this->assertEqualHTML( $expected, $printed ); 926 } finally { 927 if ( $had_compress_css ) { 928 $compress_css = $old_compress_css; 929 } else { 930 unset( $GLOBALS['compress_css'] ); 931 } 932 } 933 } 934 891 935 /** 892 936 * Tests that WP_Styles emits a _doing_it_wrong() notice for missing dependencies. 893 937 *