Make WordPress Core

Ticket #63017: 63017-small-core-clarification.diff

File 63017-small-core-clarification.diff, 9.3 KB (added by dpknauss, 6 months ago)

Small Core clarification patch: comments/docblocks, bootstrap clarity, and tests; no behavior changes intended.

  • 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 ) {  
    824824 *
    825825 * If an object-cache.php file exists in the wp-content directory,
    826826 * 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.
    827830 *
    828831 * @since 3.0.0
    829832 * @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  
    22/**
    33 * WordPress scripts and styles default loader.
    44 *
    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.
    1116 *
    1217 * 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.
    1523 *
    1624 * @package WordPress
    1725 */
    … … function print_footer_scripts() {  
    22172225 * @ignore
    22182226 *
    22192227 * @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.
    22212230 */
    22222231function _print_scripts() {
    22232232        global $wp_scripts, $compress_scripts;
    22242233
     2234        // Retain the legacy `c` query argument for compatibility with existing loader URLs.
    22252235        $zip = $compress_scripts ? 1 : 0;
    22262236        if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) {
    22272237                $zip = 'gzip';
    … … function print_late_styles() {  
    24052415 * @ignore
    24062416 * @since 3.3.0
    24072417 *
    2408  * @global bool $compress_css
     2418 * @global bool $compress_css Whether to set the legacy style loader
     2419 *                            compression URL flag.
    24092420 */
    24102421function _print_styles() {
    24112422        global $compress_css;
    24122423
    24132424        $wp_styles = wp_styles();
    24142425
     2426        // Retain the legacy `c` query argument for compatibility with existing loader URLs.
    24152427        $zip = $compress_css ? 1 : 0;
    24162428        if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) {
    24172429                $zip = 'gzip';
    … … function _print_styles() {  
    24502462}
    24512463
    24522464/**
    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.
    24542467 *
    24552468 * @since 2.8.0
    24562469 *
    24572470 * @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.
    24602475 */
    24612476function script_concat_settings() {
    24622477        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();  
    9696 *                                    Default true.
    9797 */
    9898if ( 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().
    100101        include WP_CONTENT_DIR . '/advanced-cache.php';
    101102
    102103        // Re-initialize any hooks added manually by advanced-cache.php.
    … … if ( ! isset( $GLOBALS['table_prefix'] ) ) {  
    147148// Set the database table prefix and the format specifiers for database table columns.
    148149wp_set_wpdb_vars();
    149150
    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.
    151153wp_start_object_cache();
    152154
    153155// 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;  
    20632063                $this->assertSame( $expected, $print_scripts );
    20642064        }
    20652065
     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&amp;load%5Bchunk_0%5D=one,two"
     2092                                . "&amp;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
    20662104        /**
    20672105         * Testing `wp_script_add_data` with the data key.
    20682106         *
  • 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;  
    888888                $this->assertEqualHTML( $expected, $printed );
    889889        }
    890890
     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
     923HTML;
     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
    891935        /**
    892936         * Tests that WP_Styles emits a _doing_it_wrong() notice for missing dependencies.
    893937         *