Make WordPress Core

Changeset 64585


Ignore:
Timestamp:
10/19/2026 10:45:25 PM (3 weeks ago)
Author:
westonruter
Message:

Script Loader: Retire script and style concatenation.

Scripts and styles in the admin and on the login screen are no longer concatenated through load-scripts.php and load-styles.php. Concatenation paid off when browsers opened few connections per host over HTTP/1.1, but it has long been a source of bugs: dependencies outside the default directories were not honored, SCRIPT_DEBUG and the script_loader_src and style_loader_src filters were ignored, inline styles could be duplicated, and code run by the loaders without WordPress loaded caused fatal errors. It was turned off by default in r64320, once the assets of the next admin screen began to be prefetched in r64120, and this removes what remains.

Every item is now printed as its own tag, and what remains of the concatenation API is deprecated or removed:

  • The properties of WP_Scripts and WP_Styles that held items back for concatenation are deprecated but still declared, so plugins reading or setting them keep working. The do_item() methods no longer check do_concat.
  • The _print_scripts(), _print_styles(), script_concat_settings(), in_default_dir() and WP_Dependencies::get_etag() functions are deprecated.
  • The print_head_scripts, print_footer_scripts, print_admin_styles and print_late_styles filters only decided whether held markup was printed, so they are applied with apply_filters_deprecated() and their return values are ignored.
  • The CONCATENATE_SCRIPTS constant is no longer read.
  • The wp_should_concatenate_admin_scripts() function and its filter, added in r64120 for the transition and never released, are removed.

The loaders now respond with 410 Gone and a one-line plain text explanation, without loading WordPress, so that requests from bots and stale links cost next to nothing. Code written to run inside them without WordPress loaded, such as wp_theme_has_theme_json(), now uses the functions it had avoided, and wp-admin/includes/noop.php no longer defines its stub functions.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/14463.
Follow-up to r10357, r43580, r60719, r62657, r64120, r64320, r64485.

Props westonruter, jonsurrell, peterwilsoncc, azaozz, markhowellsmead, sergiomdgomes, jerclarke, adamsilverstein, sukhendu2002, adnan007, momo360modena, desrosj, welcher.
See #15833, #36448, #36449, #36779, #43825, #45008, #47322, #52879, #63908, #64087, #65515.
Fixes #57548.

Location:
trunk
Files:
1 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r64321 r64585  
    15101510                }
    15111511
    1512                 // Check CONCATENATE_SCRIPTS.
    1513                 if ( defined( 'CONCATENATE_SCRIPTS' ) ) {
    1514                         $concatenate_scripts       = CONCATENATE_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' );
    1515                         $concatenate_scripts_debug = CONCATENATE_SCRIPTS ? 'true' : 'false';
    1516                 } else {
    1517                         $concatenate_scripts       = __( 'Undefined' );
    1518                         $concatenate_scripts_debug = 'undefined';
    1519                 }
    1520 
    15211512                // Check WP_ENVIRONMENT_TYPE.
    15221513                if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
    … …  
    15931584                                'value' => WP_CACHE ? __( 'Enabled' ) : __( 'Disabled' ),
    15941585                                'debug' => WP_CACHE,
    1595                         ),
    1596                         'CONCATENATE_SCRIPTS' => array(
    1597                                 'label' => 'CONCATENATE_SCRIPTS',
    1598                                 'value' => $concatenate_scripts,
    1599                                 'debug' => $concatenate_scripts_debug,
    16001586                        ),
    16011587                        'WP_ENVIRONMENT_TYPE' => array(
  • trunk/src/wp-admin/includes/noop.php

    r56641 r64585  
    11<?php
    22/**
    3  * Noop functions for load-scripts.php and load-styles.php.
     3 * Formerly defined noop functions for load-scripts.php and load-styles.php.
     4 *
     5 * Scripts and styles are no longer concatenated, so those files no longer load WordPress without
     6 * its functions, and these noop functions are no longer defined.
    47 *
    58 * @package WordPress
    69 * @subpackage Administration
    710 * @since 4.4.0
     11 * @deprecated 7.2.0 Scripts and styles are no longer concatenated.
    812 */
    913
    10 /**
    11  * @ignore
    12  */
    13 function __() {}
    14 
    15 /**
    16  * @ignore
    17  */
    18 function _x() {}
    19 
    20 /**
    21  * @ignore
    22  */
    23 function add_filter() {}
    24 
    25 /**
    26  * @ignore
    27  */
    28 function has_filter() {
    29         return false;
     14if ( function_exists( '_deprecated_file' ) ) {
     15        _deprecated_file( basename( __FILE__ ), '7.2.0' );
    3016}
    31 
    32 /**
    33  * @ignore
    34  */
    35 function esc_attr() {}
    36 
    37 /**
    38  * @ignore
    39  */
    40 function apply_filters() {}
    41 
    42 /**
    43  * @ignore
    44  */
    45 function get_option() {}
    46 
    47 /**
    48  * @ignore
    49  */
    50 function is_lighttpd_before_150() {}
    51 
    52 /**
    53  * @ignore
    54  */
    55 function add_action() {}
    56 
    57 /**
    58  * @ignore
    59  */
    60 function did_action() {}
    61 
    62 /**
    63  * @ignore
    64  */
    65 function do_action_ref_array() {}
    66 
    67 /**
    68  * @ignore
    69  */
    70 function get_bloginfo() {}
    71 
    72 /**
    73  * @ignore
    74  */
    75 function is_admin() {
    76         return true;
    77 }
    78 
    79 /**
    80  * @ignore
    81  */
    82 function site_url() {}
    83 
    84 /**
    85  * @ignore
    86  */
    87 function admin_url() {}
    88 
    89 /**
    90  * @ignore
    91  */
    92 function home_url() {}
    93 
    94 /**
    95  * @ignore
    96  */
    97 function includes_url() {}
    98 
    99 /**
    100  * @ignore
    101  */
    102 function wp_guess_url() {}
    103 
    104 function get_file( $path ) {
    105 
    106         $path = realpath( $path );
    107 
    108         if ( ! $path || ! @is_file( $path ) ) {
    109                 return '';
    110         }
    111 
    112         return @file_get_contents( $path );
    113 }
  • trunk/src/wp-admin/load-scripts.php

    r58935 r64585  
    11<?php
     2/**
     3 * Formerly concatenated the core scripts named in the `load` query parameter.
     4 *
     5 * Scripts are no longer concatenated, so this file now only responds with 410 Gone, for code
     6 * that still links to it directly. WordPress is not loaded, so that requests from bots and stale
     7 * links cost next to nothing and do not trigger deprecation notices.
     8 *
     9 * @package WordPress
     10 * @subpackage Administration
     11 * @deprecated 7.2.0 Scripts are no longer concatenated.
     12 */
    213
    3 /*
    4  * The error_reporting() function can be disabled in php.ini. On systems where that is the case,
    5  * it's best to add a dummy function to the wp-config.php file, but as this call to the function
    6  * is run prior to wp-config.php loading, it is wrapped in a function_exists() check.
    7  */
    8 if ( function_exists( 'error_reporting' ) ) {
    9         /*
    10          * Disable error reporting.
    11          *
    12          * Set this to error_reporting( -1 ) for debugging.
    13          */
    14         error_reporting( 0 );
    15 }
    16 
    17 // Set ABSPATH for execution.
    18 if ( ! defined( 'ABSPATH' ) ) {
    19         define( 'ABSPATH', dirname( __DIR__ ) . '/' );
    20 }
    21 
    22 define( 'WPINC', 'wp-includes' );
    23 
    24 $protocol = $_SERVER['SERVER_PROTOCOL'];
    25 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
    26         $protocol = 'HTTP/1.0';
    27 }
    28 
    29 $load = $_GET['load'];
    30 if ( is_array( $load ) ) {
    31         ksort( $load );
    32         $load = implode( '', $load );
    33 }
    34 
    35 $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
    36 $load = array_unique( explode( ',', $load ) );
    37 
    38 if ( empty( $load ) ) {
    39         header( "$protocol 400 Bad Request" );
    40         exit;
    41 }
    42 
    43 require ABSPATH . 'wp-admin/includes/noop.php';
    44 require ABSPATH . WPINC . '/script-loader.php';
    45 require ABSPATH . WPINC . '/version.php';
    46 
    47 $expires_offset = 31536000; // 1 year.
    48 $out            = '';
    49 
    50 $wp_scripts = new WP_Scripts();
    51 wp_default_scripts( $wp_scripts );
    52 wp_default_packages_vendor( $wp_scripts );
    53 wp_default_packages_scripts( $wp_scripts );
    54 
    55 $etag = $wp_scripts->get_etag( $load );
    56 
    57 if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
    58         header( "$protocol 304 Not Modified" );
    59         exit;
    60 }
    61 
    62 foreach ( $load as $handle ) {
    63         if ( ! array_key_exists( $handle, $wp_scripts->registered ) ) {
    64                 continue;
    65         }
    66 
    67         $path = ABSPATH . $wp_scripts->registered[ $handle ]->src;
    68         $out .= get_file( $path ) . "\n";
    69 }
    70 
    71 header( "Etag: $etag" );
    72 header( 'Content-Type: application/javascript; charset=UTF-8' );
    73 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
    74 header( "Cache-Control: public, max-age=$expires_offset" );
    75 
    76 echo $out;
     14http_response_code( 410 );
     15header( 'Content-Type: text/plain; charset=UTF-8' );
     16echo 'Scripts are no longer concatenated.';
    7717exit;
  • trunk/src/wp-admin/load-styles.php

    r59341 r64585  
    11<?php
     2/**
     3 * Formerly concatenated the core styles named in the `load` query parameter.
     4 *
     5 * Styles are no longer concatenated, so this file now only responds with 410 Gone, for code
     6 * that still links to it directly. WordPress is not loaded, so that requests from bots and stale
     7 * links cost next to nothing and do not trigger deprecation notices.
     8 *
     9 * @package WordPress
     10 * @subpackage Administration
     11 * @deprecated 7.2.0 Styles are no longer concatenated.
     12 */
    213
    3 /*
    4  * The error_reporting() function can be disabled in php.ini. On systems where that is the case,
    5  * it's best to add a dummy function to the wp-config.php file, but as this call to the function
    6  * is run prior to wp-config.php loading, it is wrapped in a function_exists() check.
    7  */
    8 if ( function_exists( 'error_reporting' ) ) {
    9         /*
    10          * Disable error reporting.
    11          *
    12          * Set this to error_reporting( -1 ) for debugging.
    13          */
    14         error_reporting( 0 );
    15 }
    16 
    17 // Set ABSPATH for execution.
    18 if ( ! defined( 'ABSPATH' ) ) {
    19         define( 'ABSPATH', dirname( __DIR__ ) . '/' );
    20 }
    21 
    22 define( 'WPINC', 'wp-includes' );
    23 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
    24 
    25 require ABSPATH . 'wp-admin/includes/noop.php';
    26 require ABSPATH . WPINC . '/theme.php';
    27 require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php';
    28 require ABSPATH . WPINC . '/global-styles-and-settings.php';
    29 require ABSPATH . WPINC . '/script-loader.php';
    30 require ABSPATH . WPINC . '/version.php';
    31 
    32 $protocol = $_SERVER['SERVER_PROTOCOL'];
    33 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
    34         $protocol = 'HTTP/1.0';
    35 }
    36 
    37 $load = $_GET['load'];
    38 if ( is_array( $load ) ) {
    39         ksort( $load );
    40         $load = implode( '', $load );
    41 }
    42 
    43 $load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
    44 $load = array_unique( explode( ',', $load ) );
    45 
    46 if ( empty( $load ) ) {
    47         header( "$protocol 400 Bad Request" );
    48         exit;
    49 }
    50 
    51 $rtl            = ( isset( $_GET['dir'] ) && 'rtl' === $_GET['dir'] );
    52 $expires_offset = 31536000; // 1 year.
    53 $out            = '';
    54 
    55 $wp_styles = new WP_Styles();
    56 wp_default_styles( $wp_styles );
    57 
    58 $etag = $wp_styles->get_etag( $load );
    59 
    60 if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
    61         header( "$protocol 304 Not Modified" );
    62         exit;
    63 }
    64 
    65 foreach ( $load as $handle ) {
    66         if ( ! array_key_exists( $handle, $wp_styles->registered ) ) {
    67                 continue;
    68         }
    69 
    70         $style = $wp_styles->registered[ $handle ];
    71 
    72         if ( empty( $style->src ) ) {
    73                 continue;
    74         }
    75 
    76         $path = ABSPATH . $style->src;
    77 
    78         if ( $rtl && ! empty( $style->extra['rtl'] ) ) {
    79                 // All default styles have fully independent RTL files.
    80                 $path = str_replace( '.min.css', '-rtl.min.css', $path );
    81         }
    82 
    83         $content = get_file( $path ) . "\n";
    84 
    85         // Note: str_starts_with() is not used here, as wp-includes/compat.php is not loaded in this file.
    86         if ( 0 === strpos( $style->src, '/' . WPINC . '/css/' ) ) {
    87                 $content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
    88                 $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content );
    89                 $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content );
    90                 $out    .= $content;
    91         } else {
    92                 $out .= str_replace( '../images/', 'images/', $content );
    93         }
    94 }
    95 
    96 header( "Etag: $etag" );
    97 header( 'Content-Type: text/css; charset=UTF-8' );
    98 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
    99 header( "Cache-Control: public, max-age=$expires_offset" );
    100 
    101 echo $out;
     14http_response_code( 410 );
     15header( 'Content-Type: text/plain; charset=UTF-8' );
     16echo 'Styles are no longer concatenated.';
    10217exit;
  • trunk/src/wp-includes/class-wp-dependencies.php

    r64235 r64585  
    535535         *
    536536         * @since 6.7.0
     537         * @deprecated 7.2.0 Scripts and styles are no longer concatenated by load-scripts.php or load-styles.php.
    537538         *
    538539         * @global string $wp_version The WordPress version string.
    … …  
    544545         */
    545546        public function get_etag( $load ) {
    546                 /*
    547                  * Note: wp_get_wp_version() is not used here, as this file can be included
    548                  * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
    549                  * wp-includes/functions.php is not loaded.
    550                  */
    551547                global $wp_version;
     548
     549                _deprecated_function( __METHOD__, '7.2.0' );
    552550
    553551                $etag = "WP:{$wp_version};";
  • trunk/src/wp-includes/class-wp-editor.php

    r64320 r64585  
    15201520         * Force uncompressed TinyMCE when a custom theme has been defined.
    15211521         *
    1522          * The compressed TinyMCE file cannot deal with custom themes, so this makes
    1523          * sure that WordPress uses the uncompressed TinyMCE file if a theme is defined.
    1524          * Even if the website is running on a production environment.
     1522         * The `wp-tinymce.js` bundle cannot deal with custom themes. Core registers
     1523         * the separate TinyMCE files, but a site can still register the bundle under
     1524         * the `wp-tinymce` handle, so this makes sure that the separate files are used
     1525         * if a theme is defined.
    15251526         *
    15261527         * @since 5.0.0
    … …  
    15491550         *
    15501551         * @since 4.8.0
    1551          *
    1552          * @global bool $concatenate_scripts
    15531552         */
    15541553        public static function print_tinymce_scripts() {
    1555                 global $concatenate_scripts;
    1556 
    15571554                if ( self::$tinymce_scripts_printed ) {
    15581555                        return;
    … …  
    15601557
    15611558                self::$tinymce_scripts_printed = true;
    1562 
    1563                 if ( ! isset( $concatenate_scripts ) ) {
    1564                         script_concat_settings();
    1565                 }
    15661559
    15671560                wp_print_scripts( array( 'wp-tinymce' ) );
  • trunk/src/wp-includes/class-wp-scripts.php

    r64120 r64585  
    5858         *
    5959         * @since 2.8.0
     60         * @deprecated 7.2.0 Scripts are no longer concatenated.
    6061         * @var string
    6162         */
    … …  
    7576         *
    7677         * @since 2.8.0
     78         * @deprecated 7.2.0 Scripts are no longer concatenated.
    7779         * @var bool
    7880         */
    … …  
    8486         *
    8587         * @since 2.8.0
     88         * @deprecated 7.2.0 Scripts are no longer concatenated.
    8689         * @var string
    8790         */
    … …  
    9295         *
    9396         * @since 2.8.0
     97         * @deprecated 7.2.0 Scripts are no longer concatenated.
    9498         * @var string
    9599         */
    … …  
    103107         *
    104108         * @since 2.8.0
     109         * @deprecated 7.2.0 Scripts are no longer concatenated.
    105110         * @var string
    106111         */
    … …  
    114119         *
    115120         * @since 2.8.0
     121         * @deprecated 7.2.0 Scripts are no longer concatenated.
    116122         * @var string
    117123         */
    … …  
    121127         * List of default directories.
    122128         *
    123          * @since 2.8.0
     129         * Only the deprecated {@see WP_Scripts::in_default_dir()} reads this, but
     130         * {@see wp_default_scripts()} still sets it for plugins that read it.
     131         *
     132         * @since 2.8.0
     133         * @deprecated 7.2.0 Scripts are no longer concatenated.
     134         * @see WP_Scripts::in_default_dir()
    124135         * @see wp_default_scripts()
    125136         * @var string[]|null
    … …  
    225236        public function print_extra_script( $handle, $display = true ) {
    226237                $output = $this->get_data( $handle, 'data' );
    227                 if ( ! $output ) {
     238                if ( ! is_string( $output ) || ! $output ) {
    228239                        return null;
    229240                }
    230241
    231                 /*
    232                  * Do not print a sourceURL comment if concatenation is enabled.
    233                  *
    234                  * Extra scripts may be concatenated into a single script.
    235                  * The line-based sourceURL comments may break concatenated scripts
    236                  * and do not make sense when multiple scripts are joined together.
    237                  */
    238                 if ( ! $this->do_concat ) {
    239                         $output .= sprintf(
    240                                 "\n//# sourceURL=%s",
    241                                 rawurlencode( "{$handle}-js-extra" )
    242                         );
    243                 }
     242                $output .= sprintf(
     243                        "\n//# sourceURL=%s",
     244                        rawurlencode( "{$handle}-js-extra" )
     245                );
    244246
    245247                if ( ! $display ) {
    … …  
    301303                if ( $obj->extra['conditional'] ?? false ) {
    302304                        return false;
    303                 }
    304 
    305                 if ( null === $obj->ver ) {
    306                         $ver = '';
    307                 } else {
    308                         $ver = $obj->ver ? $obj->ver : $this->default_version;
    309                 }
    310 
    311                 if ( isset( $this->args[ $handle ] ) ) {
    312                         $ver = $ver ? $ver . '&amp;' . $this->args[ $handle ] : $this->args[ $handle ];
    313305                }
    314306
    … …  
    349341                }
    350342
    351                 /*
    352                  * Prevent concatenation of scripts if the text domain is defined
    353                  * to ensure the dependency order is respected.
    354                  */
    355                 $translations_stop_concat = ! empty( $obj->textdomain );
    356 
    357343                $translations = $this->print_translations( $handle, false );
    358344                if ( $translations ) {
    … …  
    369355                }
    370356
    371                 if ( $this->do_concat ) {
    372                         /**
    373                          * Filters the script loader source.
    374                          *
    375                          * @since 2.2.0
    376                          *
    377                          * @param string $src    Script loader source path.
    378                          * @param string $handle Script handle.
    379                          */
    380                         $filtered_src = apply_filters( 'script_loader_src', $src, $handle );
    381 
    382                         if (
    383                                 is_string( $filtered_src )
    384                                 && $this->in_default_dir( $filtered_src )
    385                                 && ( $before_script || $after_script || $translations_stop_concat || $this->is_delayed_strategy( $strategy ) )
    386                         ) {
    387                                 $this->do_concat = false;
    388 
    389                                 // Have to print the so-far concatenated scripts right away to maintain the right order.
    390                                 _print_scripts();
    391                                 $this->reset();
    392                         } elseif ( $this->in_default_dir( $filtered_src ) ) {
    393                                 $this->print_code     .= $this->print_extra_script( $handle, false );
    394                                 $this->concat         .= "$handle,";
    395                                 $this->concat_version .= "$handle$ver";
    396                                 return true;
    397                         } else {
    398                                 $this->ext_handles .= "$handle,";
    399                                 $this->ext_version .= "$handle$ver";
    400                         }
    401                 }
    402 
    403357                $this->print_extra_script( $handle );
    404358
    … …  
    406360                if ( ! $src ) {
    407361                        if ( $inline_script_tag ) {
    408                                 if ( $this->do_concat ) {
    409                                         $this->print_html .= $inline_script_tag;
    410                                 } else {
    411                                         echo $inline_script_tag;
    412                                 }
     362                                echo $inline_script_tag;
    413363                        }
    414364
    … …  
    466416                $tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );
    467417
    468                 if ( $this->do_concat ) {
    469                         $this->print_html .= $tag;
    470                 } else {
    471                         echo $tag;
    472                 }
     418                echo $tag;
    473419
    474420                return true;
    … …  
    532478                }
    533479
    534                 /** This filter is documented in wp-includes/class-wp-scripts.php */
     480                /**
     481                 * Filters the script loader source.
     482                 *
     483                 * @since 2.2.0
     484                 *
     485                 * @param string $src    Script loader source path.
     486                 * @param string $handle Script handle.
     487                 */
    535488                $src = apply_filters( 'script_loader_src', $src, $handle );
    536489
    … …  
    611564                }
    612565
    613                 /*
    614                  * Print sourceURL comment regardless of concatenation.
    615                  *
    616                  * Inline scripts prevent scripts from being concatenated, so
    617                  * sourceURL comments are safe to print for inline scripts.
    618                  */
    619566                $data[] = sprintf(
    620567                        '//# sourceURL=%s',
    … …  
    872819         *
    873820         * @since 2.8.0
     821         * @deprecated 7.2.0 Scripts are no longer concatenated.
    874822         *
    875823         * @param string $src The source of the enqueued script.
    … …  
    877825         */
    878826        public function in_default_dir( $src ) {
     827                _deprecated_function( __METHOD__, '7.2.0' );
     828
    879829                if ( ! $this->default_dirs ) {
    880830                        return true;
  • trunk/src/wp-includes/class-wp-styles.php

    r64120 r64585  
    5959         *
    6060         * @since 2.8.0
     61         * @deprecated 7.2.0 Styles are no longer concatenated.
    6162         * @var string
    6263         */
    … …  
    7677         *
    7778         * @since 2.8.0
     79         * @deprecated 7.2.0 Styles are no longer concatenated.
    7880         * @var bool
    7981         */
    … …  
    8587         *
    8688         * @since 2.8.0
     89         * @deprecated 7.2.0 Styles are no longer concatenated.
    8790         * @var string
    8891         */
    … …  
    9396         *
    9497         * @since 3.3.0
     98         * @deprecated 7.2.0 Styles are no longer concatenated.
    9599         * @var string
    96100         */
    … …  
    100104         * List of default directories.
    101105         *
    102          * @since 2.8.0
     106         * Only the deprecated {@see WP_Styles::in_default_dir()} reads this, but
     107         * {@see wp_default_styles()} still sets it for plugins that read it.
     108         *
     109         * @since 2.8.0
     110         * @deprecated 7.2.0 Styles are no longer concatenated.
     111         * @see WP_Styles::in_default_dir()
    103112         * @see wp_default_styles()
    104113         * @var string[]|null
    … …  
    145154                        return false;
    146155                }
    147                 if ( null === $obj->ver ) {
    148                         $ver = '';
    149                 } else {
    150                         $ver = $obj->ver ? $obj->ver : $this->default_version;
    151                 }
    152 
    153                 if ( isset( $this->args[ $handle ] ) ) {
    154                         $ver = $ver ? $ver . '&amp;' . $this->args[ $handle ] : $this->args[ $handle ];
    155                 }
    156156
    157157                $src          = $obj->src;
    … …  
    168168                }
    169169
    170                 if ( $this->do_concat ) {
    171                         if ( is_string( $src ) && $this->in_default_dir( $src ) && ! isset( $obj->extra['alt'] ) ) {
    172                                 $this->concat         .= "$handle,";
    173                                 $this->concat_version .= "$handle$ver";
    174 
    175                                 $this->print_code .= $inline_style;
    176 
    177                                 return true;
    178                         }
    179                 }
    180 
    181170                $media = $obj->args ?? 'all';
    182171
    … …  
    184173                if ( ! $src ) {
    185174                        if ( $inline_style_tag ) {
    186                                 if ( $this->do_concat ) {
    187                                         $this->print_html .= $inline_style_tag;
    188                                 } else {
    189                                         echo $inline_style_tag;
    190                                 }
     175                                echo $inline_style_tag;
    191176                        }
    192177
    … …  
    248233                }
    249234
    250                 if ( $this->do_concat ) {
    251                         $this->print_html .= $tag;
    252                         if ( $inline_style_tag ) {
    253                                 $this->print_html .= $inline_style_tag;
    254                         }
    255                 } else {
    256                         echo $tag;
    257                         $this->print_inline_style( $handle );
    258                 }
     235                echo $tag;
     236                echo $inline_style_tag;
    259237
    260238                return true;
    … …  
    351329                }
    352330
    353                 if ( ! $this->do_concat ) {
    354 
    355                         // Obtain the original `src` for a stylesheet possibly inlined by wp_maybe_inline_styles().
    356                         $inlined_src = $this->get_data( $handle, 'inlined_src' );
    357 
    358                         // If there's only one `after` inline style, and that inline style had been inlined, then use the $inlined_src
    359                         // as the sourceURL. Otherwise, if there is more than one inline `after` style associated with the handle,
    360                         // then resort to using the handle to construct the sourceURL since there isn't a single source.
    361                         if ( count( $output ) === 1 && is_string( $inlined_src ) && strlen( $inlined_src ) > 0 ) {
    362                                 $source_url = esc_url_raw( $inlined_src );
    363                         } else {
    364                                 $source_url = rawurlencode( "{$handle}-inline-css" );
    365                         }
    366 
    367                         $output[] = sprintf(
    368                                 '/*# sourceURL=%s */',
    369                                 $source_url
    370                         );
    371                 }
     331                // Obtain the original `src` for a stylesheet possibly inlined by wp_maybe_inline_styles().
     332                $inlined_src = $this->get_data( $handle, 'inlined_src' );
     333
     334                // If there's only one `after` inline style, and that inline style had been inlined, then use the $inlined_src
     335                // as the sourceURL. Otherwise, if there is more than one inline `after` style associated with the handle,
     336                // then resort to using the handle to construct the sourceURL since there isn't a single source.
     337                if ( count( $output ) === 1 && is_string( $inlined_src ) && strlen( $inlined_src ) > 0 ) {
     338                        $source_url = esc_url_raw( $inlined_src );
     339                } else {
     340                        $source_url = rawurlencode( "{$handle}-inline-css" );
     341                }
     342
     343                $output[] = sprintf(
     344                        '/*# sourceURL=%s */',
     345                        $source_url
     346                );
    372347
    373348                $output = implode( "\n", $output );
    … …  
    553528         *
    554529         * @since 2.8.0
     530         * @deprecated 7.2.0 Styles are no longer concatenated.
    555531         *
    556532         * @param string $src The source of the enqueued style.
    … …  
    558534         */
    559535        public function in_default_dir( $src ) {
     536                _deprecated_function( __METHOD__, '7.2.0' );
     537
    560538                if ( ! $this->default_dirs ) {
    561539                        return true;
  • trunk/src/wp-includes/default-constants.php

    r64115 r64585  
    116116
    117117        /*
    118          * Add define( 'SCRIPT_DEBUG', true ); to wp-config.php to enable loading of non-minified,
    119          * non-concatenated scripts and stylesheets.
     118         * Add define( 'SCRIPT_DEBUG', true ); to wp-config.php to enable loading of non-minified
     119         * scripts and stylesheets.
    120120         */
    121121        if ( ! defined( 'SCRIPT_DEBUG' ) ) {
  • trunk/src/wp-includes/deprecated.php

    r64489 r64585  
    66036603
    66046604/**
     6605 * Determines the concatenation settings for scripts and styles.
     6606 *
     6607 * Scripts and styles are no longer concatenated, so this only gives the `$concatenate_scripts`,
     6608 * `$compress_scripts`, and `$compress_css` globals a value of false when they are not already set,
     6609 * for code that still reads them.
     6610 *
     6611 * @since 2.8.0
     6612 * @since 7.2.0 The `$compress_scripts` and `$compress_css` globals default to false, as PHP compression
     6613 *              of scripts and styles was removed in 4.9.9.
     6614 * @deprecated 7.2.0 Scripts and styles are no longer concatenated.
     6615 *
     6616 * @global bool $concatenate_scripts
     6617 * @global bool $compress_scripts
     6618 * @global bool $compress_css
     6619 */
     6620function script_concat_settings(): void {
     6621        global $concatenate_scripts, $compress_scripts, $compress_css;
     6622
     6623        _deprecated_function( __FUNCTION__, '7.2.0' );
     6624
     6625        if ( ! isset( $concatenate_scripts ) ) {
     6626                $concatenate_scripts = false;
     6627        }
     6628
     6629        if ( ! isset( $compress_scripts ) ) {
     6630                $compress_scripts = false;
     6631        }
     6632
     6633        if ( ! isset( $compress_css ) ) {
     6634                $compress_css = false;
     6635        }
     6636}
     6637
     6638/**
     6639 * Prints scripts (internal use only)
     6640 *
     6641 * @since 2.8.0
     6642 * @deprecated 7.2.0 Scripts are no longer concatenated.
     6643 *
     6644 * @ignore
     6645 *
     6646 * @global WP_Scripts $wp_scripts
     6647 */
     6648function _print_scripts(): void {
     6649        global $wp_scripts;
     6650
     6651        _deprecated_function( __FUNCTION__, '7.2.0' );
     6652
     6653        if ( ! empty( $wp_scripts->print_html ) ) {
     6654                echo $wp_scripts->print_html;
     6655        }
     6656}
     6657
     6658/**
     6659 * Prints styles (internal use only).
     6660 *
     6661 * @ignore
     6662 * @since 3.3.0
     6663 * @deprecated 7.2.0 Styles are no longer concatenated.
     6664 */
     6665function _print_styles(): void {
     6666        _deprecated_function( __FUNCTION__, '7.2.0' );
     6667
     6668        $wp_styles = wp_styles();
     6669
     6670        if ( ! empty( $wp_styles->print_html ) ) {
     6671                echo $wp_styles->print_html;
     6672        }
     6673}
     6674
     6675/**
    66056676 * Starts an output buffer that sends the Document-Isolation-Policy header
    66066677 * and adds crossorigin="anonymous" to cross-origin resources.
  • trunk/src/wp-includes/global-styles-and-settings.php

    r64436 r64585  
    388388        }
    389389
    390         $stylesheet_directory = get_stylesheet_directory();
    391         $template_directory   = get_template_directory();
    392 
    393         // This is the same as get_theme_file_path(), which isn't available in load-styles.php context
    394         if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) {
    395                 $path = $stylesheet_directory . '/theme.json';
    396         } else {
    397                 $path = $template_directory . '/theme.json';
    398         }
    399 
    400         /** This filter is documented in wp-includes/link-template.php */
    401         $path = apply_filters( 'theme_file_path', $path, 'theme.json' );
     390        $path = get_theme_file_path( 'theme.json' );
    402391
    403392        $theme_has_support[ $stylesheet ] = file_exists( $path );
  • trunk/src/wp-includes/script-loader.php

    r64496 r64585  
    33 * WordPress scripts and styles default loader.
    44 *
    5  * These constants are used to manage the loading and concatenating of scripts and CSS:
    6  * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS, and disables concatenation,
    7  * define('CONCATENATE_SCRIPTS', true); enables concatenation of scripts and CSS in the admin and on the login screen (disabled by default).
    8  *
    9  * The global $concatenate_scripts can be set by plugins to temporarily override the above settings.
     5 * This constant is used to manage the loading of scripts and CSS:
     6 * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS.
    107 *
    118 * @package WordPress
    … …  
    5956        $suffix     = wp_scripts_get_suffix();
    6057        $dev_suffix = wp_scripts_get_suffix( 'dev' );
    61 
    62         /*
    63          * This no longer depends on the concatenation settings, but it is where an admin screen has
    64          * settled them until now, which the 'wp_should_concatenate_admin_scripts' filter documents.
    65          */
    66         script_concat_settings();
    6758
    6859        // Load tinymce.js when running from /src, otherwise tinymce.min.js.
    … …  
    693684
    694685        if ( null === $suffixes ) {
    695                 /*
    696                  * Include an unmodified $wp_version.
    697                  *
    698                  * Note: wp_get_wp_version() is not used here, as this file can be included
    699                  * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
    700                  * wp-includes/functions.php is not loaded.
    701                  */
    702                 require ABSPATH . WPINC . '/version.php';
    703 
    704                 /*
    705                  * Note: str_contains() is not used here, as this file can be included
    706                  * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
    707                  * the polyfills from wp-includes/compat.php are not loaded.
    708                  */
    709                 $develop_src = false !== strpos( $wp_version, '-src' );
     686                $develop_src = str_contains( wp_get_wp_version(), '-src' );
    710687
    711688                if ( ! defined( 'SCRIPT_DEBUG' ) ) {
    … …  
    752729        $scripts->content_url     = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
    753730        $scripts->default_version = get_bloginfo( 'version' );
    754         $scripts->default_dirs    = array( '/wp-admin/js/', '/wp-includes/js/' );
     731        $scripts->default_dirs    = array( '/wp-admin/js/', '/wp-includes/js/' ); // Deprecated, but still set for plugins that read it.
    755732
    756733        $scripts->add( 'utils', "/wp-includes/js/utils$suffix.js" );
    … …  
    15601537        global $editor_styles;
    15611538
    1562         /*
    1563          * Include an unmodified $wp_version.
    1564          *
    1565          * Note: wp_get_wp_version() is not used here, as this file can be included
    1566          * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
    1567          * wp-includes/functions.php is not loaded.
    1568          */
    1569         require ABSPATH . WPINC . '/version.php';
    1570 
    1571         if ( ! defined( 'SCRIPT_DEBUG' ) ) {
    1572                 /*
    1573                  * Note: str_contains() is not used here, as this file can be included
    1574                  * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
    1575                  * the polyfills from wp-includes/compat.php are not loaded.
    1576                  */
    1577                 define( 'SCRIPT_DEBUG', false !== strpos( $wp_version, '-src' ) );
    1578         }
    1579 
    15801539        $guessurl = site_url();
    15811540
    … …  
    15871546        $styles->content_url     = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
    15881547        $styles->default_version = get_bloginfo( 'version' );
    1589         $styles->text_direction  = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';
    1590         $styles->default_dirs    = array( '/wp-admin/', '/wp-includes/css/' );
     1548        $styles->text_direction  = is_rtl() ? 'rtl' : 'ltr';
     1549        $styles->default_dirs    = array( '/wp-admin/', '/wp-includes/css/' ); // Deprecated, but still set for plugins that read it.
    15911550
    15921551        // Open Sans is no longer used by core, but may be relied upon by themes and plugins.
    … …  
    16211580        $styles->add( 'colors', true, array( 'wp-admin', 'buttons' ) );
    16221581
    1623         $suffix = SCRIPT_DEBUG ? '' : '.min';
     1582        $suffix = wp_scripts_get_suffix();
    16241583
    16251584        // Admin CSS.
    … …  
    21582117 * @see wp_print_scripts()
    21592118 *
    2160  * @global bool $concatenate_scripts
    2161  *
    21622119 * @return string[] Handles of the scripts that were printed.
    21632120 */
    21642121function print_head_scripts() {
    2165         global $concatenate_scripts;
    2166 
    21672122        if ( ! did_action( 'wp_print_scripts' ) ) {
    21682123                /** This action is documented in wp-includes/functions.wp-scripts.php */
    … …  
    21712126
    21722127        $wp_scripts = wp_scripts();
    2173 
    2174         script_concat_settings();
    2175         $wp_scripts->do_concat = $concatenate_scripts;
    21762128        $wp_scripts->do_head_items();
    21772129
    … …  
    21802132         *
    21812133         * @since 2.8.0
     2134         * @deprecated 7.2.0 Scripts are no longer concatenated, so there is nothing for this filter to control.
    21822135         *
    21832136         * @param bool $print Whether to print the head scripts. Default true.
    21842137         */
    2185         if ( apply_filters( 'print_head_scripts', true ) ) {
    2186                 _print_scripts();
    2187         }
     2138        apply_filters_deprecated( 'print_head_scripts', array( true ), '7.2.0' );
    21882139
    21892140        $wp_scripts->reset();
    … …  
    21972148 *
    21982149 * @global WP_Scripts $wp_scripts
    2199  * @global bool       $concatenate_scripts
    22002150 *
    22012151 * @return string[] Handles of the scripts that were printed.
    22022152 */
    22032153function print_footer_scripts() {
    2204         global $wp_scripts, $concatenate_scripts;
     2154        global $wp_scripts;
    22052155
    22062156        if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    22072157                return array(); // No need to run if not instantiated.
    22082158        }
    2209         script_concat_settings();
    2210         $wp_scripts->do_concat = $concatenate_scripts;
    22112159        $wp_scripts->do_footer_items();
    22122160
    … …  
    22152163         *
    22162164         * @since 2.8.0
     2165         * @deprecated 7.2.0 Scripts are no longer concatenated, so there is nothing for this filter to control.
    22172166         *
    22182167         * @param bool $print Whether to print the footer scripts. Default true.
    22192168         */
    2220         if ( apply_filters( 'print_footer_scripts', true ) ) {
    2221                 _print_scripts();
    2222         }
     2169        apply_filters_deprecated( 'print_footer_scripts', array( true ), '7.2.0' );
    22232170
    22242171        $wp_scripts->reset();
    22252172        return $wp_scripts->done;
    2226 }
    2227 
    2228 /**
    2229  * Prints scripts (internal use only)
    2230  *
    2231  * @since 2.8.0
    2232  *
    2233  * @ignore
    2234  *
    2235  * @global WP_Scripts $wp_scripts
    2236  */
    2237 function _print_scripts() {
    2238         global $wp_scripts;
    2239 
    2240         $concat = trim( $wp_scripts->concat, ', ' );
    2241 
    2242         if ( $concat ) {
    2243                 if ( ! empty( $wp_scripts->print_code ) ) {
    2244                         wp_print_inline_script_tag( $wp_scripts->print_code . "\n//# sourceURL=" . rawurlencode( 'js-inline-concat-' . $concat ) );
    2245                 }
    2246 
    2247                 $concat       = str_split( $concat, 128 );
    2248                 $concatenated = '';
    2249 
    2250                 foreach ( $concat as $key => $chunk ) {
    2251                         $concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}";
    2252                 }
    2253 
    2254                 $src = $wp_scripts->base_url . '/wp-admin/load-scripts.php?' . ltrim( $concatenated, '&' ) . '&ver=' . $wp_scripts->default_version;
    2255                 wp_print_script_tag( array( 'src' => $src ) );
    2256         }
    2257 
    2258         if ( ! empty( $wp_scripts->print_html ) ) {
    2259                 echo $wp_scripts->print_html;
    2260         }
    22612173}
    22622174
    … …  
    23432255 * @since 2.8.0
    23442256 *
    2345  * @global bool $concatenate_scripts
    2346  *
    23472257 * @return string[] Handles of the styles that were printed.
    23482258 */
    23492259function print_admin_styles() {
    2350         global $concatenate_scripts;
    2351 
    23522260        $wp_styles = wp_styles();
    2353 
    2354         script_concat_settings();
    2355         $wp_styles->do_concat = $concatenate_scripts;
    23562261        $wp_styles->do_items( false );
    23572262
    … …  
    23602265         *
    23612266         * @since 2.8.0
     2267         * @deprecated 7.2.0 Styles are no longer concatenated, so there is nothing for this filter to control.
    23622268         *
    23632269         * @param bool $print Whether to print the admin styles. Default true.
    23642270         */
    2365         if ( apply_filters( 'print_admin_styles', true ) ) {
    2366                 _print_styles();
    2367         }
     2271        apply_filters_deprecated( 'print_admin_styles', array( true ), '7.2.0' );
    23682272
    23692273        $wp_styles->reset();
    … …  
    23772281 *
    23782282 * @global WP_Styles $wp_styles
    2379  * @global bool      $concatenate_scripts
    23802283 *
    23812284 * @return string[]|null
    23822285 */
    23832286function print_late_styles() {
    2384         global $wp_styles, $concatenate_scripts;
     2287        global $wp_styles;
    23852288
    23862289        if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    … …  
    23882291        }
    23892292
    2390         script_concat_settings();
    2391         $wp_styles->do_concat = $concatenate_scripts;
    23922293        $wp_styles->do_footer_items();
    23932294
    … …  
    23962297         *
    23972298         * @since 3.3.0
     2299         * @deprecated 7.2.0 Styles are no longer concatenated, so there is nothing for this filter to control.
    23982300         *
    23992301         * @param bool $print Whether to print the 'late' styles. Default true.
    24002302         */
    2401         if ( apply_filters( 'print_late_styles', true ) ) {
    2402                 _print_styles();
    2403         }
     2303        apply_filters_deprecated( 'print_late_styles', array( true ), '7.2.0' );
    24042304
    24052305        $wp_styles->reset();
    … …  
    24082308
    24092309/**
    2410  * Prints styles (internal use only).
    2411  *
    2412  * @ignore
    2413  * @since 3.3.0
    2414  */
    2415 function _print_styles() {
    2416         $wp_styles = wp_styles();
    2417 
    2418         $concat = trim( $wp_styles->concat, ', ' );
    2419 
    2420         if ( $concat ) {
    2421                 $dir = $wp_styles->text_direction;
    2422                 $ver = $wp_styles->default_version;
    2423 
    2424                 $concat_source_url = 'css-inline-concat-' . $concat;
    2425                 $concat            = str_split( $concat, 128 );
    2426                 $concatenated      = '';
    2427 
    2428                 foreach ( $concat as $key => $chunk ) {
    2429                         $concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}";
    2430                 }
    2431 
    2432                 $href = $wp_styles->base_url . "/wp-admin/load-styles.php?dir={$dir}" . $concatenated . '&ver=' . $ver;
    2433                 echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "' media='all' />\n";
    2434 
    2435                 if ( ! empty( $wp_styles->print_code ) ) {
    2436                         $processor = new WP_HTML_Tag_Processor( '<style></style>' );
    2437                         $processor->next_tag();
    2438                         $style_tag_contents = "\n{$wp_styles->print_code}\n"
    2439                                 . sprintf( "/*# sourceURL=%s */\n", rawurlencode( $concat_source_url ) );
    2440                         $processor->set_modifiable_text( $style_tag_contents );
    2441                         echo "{$processor->get_updated_html()}\n";
    2442                 }
    2443         }
    2444 
    2445         if ( ! empty( $wp_styles->print_html ) ) {
    2446                 echo $wp_styles->print_html;
    2447         }
    2448 }
    2449 
    2450 /**
    2451  * Determines the concatenation settings for scripts and styles.
    2452  *
    2453  * @since 2.8.0
    2454  * @since 7.2.0 The `$compress_scripts` and `$compress_css` globals default to false, as PHP compression
    2455  *              of scripts and styles was removed in 4.9.9.
    2456  *
    2457  * @global bool $concatenate_scripts
    2458  * @global bool $compress_scripts
    2459  * @global bool $compress_css
    2460  */
    2461 function script_concat_settings() {
    2462         global $concatenate_scripts, $compress_scripts, $compress_css;
    2463 
    2464         if ( ! isset( $concatenate_scripts ) ) {
    2465                 $concatenate_scripts = ( is_admin() || did_action( 'login_init' ) ) && wp_should_concatenate_admin_scripts();
    2466         }
    2467 
    2468         if ( ! isset( $compress_scripts ) ) {
    2469                 $compress_scripts = false;
    2470         }
    2471 
    2472         if ( ! isset( $compress_css ) ) {
    2473                 $compress_css = false;
    2474         }
    2475 }
    2476 
    2477 /**
    2478  * Determines whether scripts and styles are concatenated on admin screens and the login screen.
    2479  *
    2480  * Concatenation is off unless the `CONCATENATE_SCRIPTS` constant turns it on, and `SCRIPT_DEBUG`
    2481  * turns it off regardless. Scripts and styles are never concatenated elsewhere.
    2482  *
    2483  * This is the default that script_concat_settings() gives the `$concatenate_scripts` global when
    2484  * the global has not already been set. It is also how wp_prefetch_admin_assets() predicts, from the
    2485  * login screen, what the admin screen the login leads to will do.
    2486  *
    2487  * This function and its filter are intended to be removed before 7.2-beta1. They exist only while
    2488  * concatenation is still an option, and once concatenation is retired, there is nothing left for
    2489  * them to decide. Do not rely on them; setting the `$concatenate_scripts` global remains the way
    2490  * to override concatenation on a request.
    2491  *
    2492  * @since 7.2.0
    2493  *
    2494  * @return bool Whether scripts and styles are concatenated on admin screens and the login screen.
    2495  */
    2496 function wp_should_concatenate_admin_scripts(): bool {
    2497         $concatenate = ( defined( 'CONCATENATE_SCRIPTS' ) ? (bool) CONCATENATE_SCRIPTS : false )
    2498                 && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG );
    2499 
    2500         /**
    2501          * Filters whether scripts and styles are concatenated on admin screens and the login screen.
    2502          *
    2503          * Setting the `$concatenate_scripts` global directly still takes precedence over this filter on
    2504          * the request where it is set.
    2505          *
    2506          * An admin screen settles the global the first time scripts are registered, when the
    2507          * {@see 'wp_default_scripts'} action registers TinyMCE. That can be as early as while plugins
    2508          * load, before the theme's functions.php, whereas the login screen reads this filter only when
    2509          * it prints, to predict what the admin will do. So add a callback when a plugin loads, rather
    2510          * than from a theme or on a later hook, or the admin may not see it while the login screen does.
    2511          *
    2512          * @since 7.2.0
    2513          *
    2514          * @param bool $concatenate Whether scripts and styles are concatenated. Default false, unless the
    2515          *                          `CONCATENATE_SCRIPTS` constant is true and `SCRIPT_DEBUG` is not.
    2516          */
    2517         return (bool) apply_filters( 'wp_should_concatenate_admin_scripts', $concatenate );
    2518 }
    2519 
    2520 /**
    25212310 * Prints prefetch links for the assets of the screen the user is most likely to open next.
    25222311 *
    … …  
    25242313 * screen is certain to need. Two cases qualify today:
    25252314 *
    2526  * - The login screen, which is followed by an admin screen. With concatenation disabled that
    2527  *   screen downloads each core script and stylesheet separately, which is what makes an uncached
    2528  *   admin load slower than a concatenated one. Requesting the ones that block its first paint
    2529  *   while the login form is on screen puts them in the HTTP cache during the time the user spends
    2530  *   typing credentials, so the redirect that follows finds them already there.
     2315 * - The login screen, which is followed by an admin screen. That screen downloads each core script
     2316 *   and stylesheet separately, which is what makes an uncached admin load slow. Requesting the
     2317 *   ones that block its first paint while the login form is on screen puts them in the HTTP cache
     2318 *   during the time the user spends typing credentials, so the redirect that follows finds them
     2319 *   already there.
    25312320 * - The Dashboard and the post list tables, from which the editor is the usual next stop. Only the
    25322321 *   editor's stylesheets are prefetched, not its scripts: the scripts run to well over a megabyte
    … …  
    25602349 * printed at all when `redirect_to` points outside this site's admin.
    25612350 *
    2562  * Nothing is printed when the next screen will concatenate its assets, since `load-scripts.php`
    2563  * and `load-styles.php` already collapse these handles into a handful of requests.
    2564  *
    25652351 * @since 7.2.0
    25662352 *
    25672353 * @see wp_preload_resources()
    2568  * @see wp_should_concatenate_admin_scripts()
    2569  *
    2570  * @global bool           $concatenate_scripts Whether scripts and styles are concatenated.
    2571  * @global WP_Screen|null $current_screen      The current admin screen, if any.
     2354 *
     2355 * @global WP_Screen|null $current_screen The current admin screen, if any.
    25722356 */
    25732357function wp_prefetch_admin_assets(): void {
    2574         global $concatenate_scripts, $current_screen;
     2358        global $current_screen;
    25752359
    25762360        /*
    25772361         * The context is told apart by the request rather than by the hook this runs on, so it works
    25782362         * from whichever hook it is added to. The 'login_init' action is fired by wp-login.php however
    2579          * it is reached, which is also how script_concat_settings() recognizes it. The is_login()
    2580          * function would not do: it compares the login URL with the script handling the request, and a
    2581          * plugin serving the login screen at a URL of its own runs wp-login.php from another script,
    2582          * such as index.php.
     2363         * it is reached. The is_login() function would not do: it compares the login URL with the
     2364         * script handling the request, and a plugin serving the login screen at a URL of its own runs
     2365         * wp-login.php from another script, such as index.php.
    25832366         */
    25842367        $on_login = (bool) did_action( 'login_init' );
    25852368
    2586         if ( $on_login ) {
    2587                 /*
    2588                  * Deliberately not the $concatenate_scripts global: script_concat_settings() often runs on a
    2589                  * login request before 'login_init' fires — anything registering a script on 'init' is enough
    2590                  * to trigger it — and at that point it evaluates is_admin() as false and settles the global on
    2591                  * false whatever the constant says. What matters here is what the admin screen this login
    2592                  * leads to will do, which is what wp_should_concatenate_admin_scripts() predicts.
    2593                  */
    2594                 if ( wp_should_concatenate_admin_scripts() ) {
    2595                         return;
    2596                 }
    2597         } else {
     2369        if ( ! $on_login ) {
    25982370                /*
    25992371                 * From the Dashboard and the post list tables, the editor is the usual next stop. Anywhere
    … …  
    26052377                 */
    26062378                if ( ! $current_screen instanceof WP_Screen || ! in_array( $current_screen->base, array( 'dashboard', 'edit' ), true ) ) {
    2607                         return;
    2608                 }
    2609 
    2610                 /*
    2611                  * On an admin screen the global has settled by the time its head is printed, and the editor
    2612                  * will be served the same way.
    2613                  */
    2614                 script_concat_settings();
    2615 
    2616                 if ( $concatenate_scripts ) {
    26172379                        return;
    26182380                }
  • trunk/tests/phpstan/base.neon

    r64486 r64585  
    213213        excludePaths:
    214214                analyseAndScan:
    215                         - ../../src/wp-admin/includes/noop.php
    216215                        # Locally installed npm dependencies, such as in bundled themes, which may include PHP files.
    217216                        - */node_modules/*
    … …  
    225224                        - ../../src/wp-includes/ms-deprecated.php
    226225                        - ../../src/wp-includes/pluggable-deprecated.php
    227                         # Script and style concatenation which rely on a get_file() function in noop.php.
    228                         - ../../src/wp-admin/load-scripts.php
    229                         - ../../src/wp-admin/load-styles.php
    230226                        # These files are autogenerated by tools/gutenberg/copy.js.
    231227                        - ../../src/wp-includes/blocks
  • trunk/tests/phpstan/baselines/variable.undefined.neon

    r64582 r64585  
    785785                        path: ../../../src/wp-includes/ms-settings.php
    786786                -
    787                         message: '#^Variable \$wp_version might not be defined\.$#'
    788                         identifier: variable.undefined
    789                         count: 2
    790                         path: ../../../src/wp-includes/script-loader.php
    791                 -
    792787                        message: '#^Variable \$wp_template_path might not be defined\.$#'
    793788                        identifier: variable.undefined
  • trunk/tests/phpunit/tests/dependencies.php

    r64040 r64585  
    177177         * @ticket 58433
    178178         * @ticket 61485
     179         * @ticket 57548
    179180         *
    180181         * @covers WP_Dependencies::get_etag
     182         *
     183         * @expectedDeprecated WP_Dependencies::get_etag
    181184         *
    182185         * @dataProvider data_provider_get_etag
    … …  
    211214         * @ticket 58433
    212215         * @ticket 61485
     216         * @ticket 57548
    213217         *
    214218         * @covers WP_Dependencies::get_etag
     219         *
     220         * @expectedDeprecated WP_Dependencies::get_etag
    215221         *
    216222         * @dataProvider data_provider_get_etag
  • trunk/tests/phpunit/tests/dependencies/scriptConcatSettings.php

    r64485 r64585  
    5757
    5858        /**
     59         * Tests that the `$concatenate_scripts` global defaults to false, even on an admin screen.
     60         *
     61         * @ticket 57548
     62         *
     63         * @expectedDeprecated script_concat_settings
     64         */
     65        public function test_concatenate_scripts_global_defaults_to_false(): void {
     66                set_current_screen( 'dashboard' );
     67
     68                script_concat_settings();
     69
     70                $this->assertFalse( $GLOBALS['concatenate_scripts'] );
     71        }
     72
     73        /**
    5974         * Tests that the compression globals default to false, as scripts and styles are not compressed from PHP.
    6075         *
    6176         * @ticket 63017
     77         *
     78         * @expectedDeprecated script_concat_settings
    6279         */
    6380        public function test_compression_globals_default_to_false(): void {
    … …  
    7592         *
    7693         * @ticket 63017
     94         *
     95         * @expectedDeprecated script_concat_settings
    7796         *
    7897         * @runInSeparateProcess
    … …  
    94113         *
    95114         * @ticket 63017
     115         *
     116         * @expectedDeprecated script_concat_settings
    96117         */
    97118        public function test_compression_globals_already_set_are_kept(): void {
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r64485 r64585  
    2626class Tests_Dependencies_Scripts extends WP_UnitTestCase {
    2727
    28         /**
    29          * @var WP_Scripts
    30          */
    31         protected $old_wp_scripts;
    32 
    33         /**
    34          * @var bool
    35          */
    36         protected $old_concatenate_scripts;
    37 
    38         /**
    39          * @var WP_Styles
    40          */
    41         protected $old_wp_styles;
     28        protected ?WP_Scripts $old_wp_scripts = null;
     29
     30        protected ?WP_Styles $old_wp_styles = null;
    4231
    4332        protected $wp_scripts_print_translations_output;
    … …  
    5241        public function set_up() {
    5342                parent::set_up();
    54                 $this->old_wp_scripts          = $GLOBALS['wp_scripts'] ?? null;
    55                 $this->old_wp_styles           = $GLOBALS['wp_styles'] ?? null;
    56                 $this->old_concatenate_scripts = $GLOBALS['concatenate_scripts'] ?? null;
     43                $old_wp_scripts       = $GLOBALS['wp_scripts'] ?? null;
     44                $old_wp_styles        = $GLOBALS['wp_styles'] ?? null;
     45                $this->old_wp_scripts = $old_wp_scripts instanceof WP_Scripts ? $old_wp_scripts : null;
     46                $this->old_wp_styles  = $old_wp_styles instanceof WP_Styles ? $old_wp_styles : null;
    5747                remove_action( 'wp_default_scripts', 'wp_default_scripts' );
    5848                remove_action( 'wp_default_scripts', 'wp_default_packages' );
    … …  
    6252
    6353                $this->wp_scripts_print_translations_output  = <<<JS
    64 <script id='__HANDLE__-js-translations'>
    65 ( function( domain, translations ) {
    66         var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
    67         localeData[""].domain = domain;
    68         wp.i18n.setLocaleData( localeData, domain );
    69 } )( "__DOMAIN__", __JSON_TRANSLATIONS__ );
    70 //# sourceURL=__HANDLE__-js-translations
    71 </script>
    72 JS;
     54                <script id='__HANDLE__-js-translations'>
     55                ( function( domain, translations ) {
     56                        var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
     57                        localeData[""].domain = domain;
     58                        wp.i18n.setLocaleData( localeData, domain );
     59                } )( "__DOMAIN__", __JSON_TRANSLATIONS__ );
     60                //# sourceURL=__HANDLE__-js-translations
     61                </script>
     62                JS;
    7363                $this->wp_scripts_print_translations_output .= "\n";
    7464        }
    7565
    7666        public function tear_down() {
    77                 $GLOBALS['wp_scripts']          = $this->old_wp_scripts;
    78                 $GLOBALS['wp_styles']           = $this->old_wp_styles;
    79                 $GLOBALS['concatenate_scripts'] = $this->old_concatenate_scripts;
     67                $GLOBALS['wp_scripts'] = $this->old_wp_scripts;
     68                $GLOBALS['wp_styles']  = $this->old_wp_styles;
    8069                add_action( 'wp_default_scripts', 'wp_default_scripts' );
    8170                parent::tear_down();
    … …  
    423412                $output   = get_echo( 'wp_print_scripts' );
    424413                $expected = <<<JS
    425 <script src='/main-script-a3.js' id='main-script-a3-js' data-wp-strategy='{$strategy}'></script>
    426 <script id="dependent-script-a3-js" src="/dependent-script-a3.js"></script>
    427 
    428 JS;
     414                <script src='/main-script-a3.js' id='main-script-a3-js' data-wp-strategy='{$strategy}'></script>
     415                <script id="dependent-script-a3-js" src="/dependent-script-a3.js"></script>
     416
     417                JS;
    429418                $this->assertEqualHTML( $expected, $output, '<body>', 'Blocking dependents must force delayed dependencies to become blocking.' );
    430419        }
    … …  
    673662                                },
    674663                                'expected_markup' => <<<HTML
    675 <script id="blocking-not-async-without-dependency-js-before">
    676 scriptEventLog.push( "blocking-not-async-without-dependency: before inline" )
    677 //# sourceURL=blocking-not-async-without-dependency-js-before
    678 </script>
    679 <script src='https://example.com/external.js?script_event_log=blocking-not-async-without-dependency:%20script' id='blocking-not-async-without-dependency-js'></script>
    680 <script id="blocking-not-async-without-dependency-js-after">
    681 scriptEventLog.push( "blocking-not-async-without-dependency: after inline" )
    682 //# sourceURL=blocking-not-async-without-dependency-js-after
    683 </script>
    684 <script id="async-with-blocking-dependency-js-before">
    685 scriptEventLog.push( "async-with-blocking-dependency: before inline" )
    686 //# sourceURL=async-with-blocking-dependency-js-before
    687 </script>
    688 <script src='https://example.com/external.js?script_event_log=async-with-blocking-dependency:%20script' id='async-with-blocking-dependency-js' data-wp-strategy='async'></script>
    689 <script id="async-with-blocking-dependency-js-after">
    690 scriptEventLog.push( "async-with-blocking-dependency: after inline" )
    691 //# sourceURL=async-with-blocking-dependency-js-after
    692 </script>
    693 HTML
    694                                 ,
    695                                 /*
    696                                  * Note: The above comma must be on its own line in PHP<7.3 and not after the `HTML` identifier
    697                                  * terminating the heredoc. Otherwise, a syntax error is raised with the line number being wildly wrong:
    698                                  *
    699                                  * PHP Parse error:  syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
    700                                  */
     664                                <script id="blocking-not-async-without-dependency-js-before">
     665                                scriptEventLog.push( "blocking-not-async-without-dependency: before inline" )
     666                                //# sourceURL=blocking-not-async-without-dependency-js-before
     667                                </script>
     668                                <script src='https://example.com/external.js?script_event_log=blocking-not-async-without-dependency:%20script' id='blocking-not-async-without-dependency-js'></script>
     669                                <script id="blocking-not-async-without-dependency-js-after">
     670                                scriptEventLog.push( "blocking-not-async-without-dependency: after inline" )
     671                                //# sourceURL=blocking-not-async-without-dependency-js-after
     672                                </script>
     673                                <script id="async-with-blocking-dependency-js-before">
     674                                scriptEventLog.push( "async-with-blocking-dependency: before inline" )
     675                                //# sourceURL=async-with-blocking-dependency-js-before
     676                                </script>
     677                                <script src='https://example.com/external.js?script_event_log=async-with-blocking-dependency:%20script' id='async-with-blocking-dependency-js' data-wp-strategy='async'></script>
     678                                <script id="async-with-blocking-dependency-js-after">
     679                                scriptEventLog.push( "async-with-blocking-dependency: after inline" )
     680                                //# sourceURL=async-with-blocking-dependency-js-after
     681                                </script>
     682                                HTML,
    701683                        ),
    702684                        'async-with-async-dependencies'                => array(
    … …  
    714696                                },
    715697                                'expected_markup' => <<<HTML
    716 <script id="async-no-dependency-js-before">
    717 scriptEventLog.push( "async-no-dependency: before inline" )
    718 //# sourceURL=async-no-dependency-js-before
    719 </script>
    720 <script src='https://example.com/external.js?script_event_log=async-no-dependency:%20script' id='async-no-dependency-js' data-wp-strategy='async'></script>
    721 <script id="async-no-dependency-js-after">
    722 scriptEventLog.push( "async-no-dependency: after inline" )
    723 //# sourceURL=async-no-dependency-js-after
    724 </script>
    725 <script id="async-one-async-dependency-js-before">
    726 scriptEventLog.push( "async-one-async-dependency: before inline" )
    727 //# sourceURL=async-one-async-dependency-js-before
    728 </script>
    729 <script src='https://example.com/external.js?script_event_log=async-one-async-dependency:%20script' id='async-one-async-dependency-js' data-wp-strategy='async'></script>
    730 <script id="async-one-async-dependency-js-after">
    731 scriptEventLog.push( "async-one-async-dependency: after inline" )
    732 //# sourceURL=async-one-async-dependency-js-after
    733 </script>
    734 <script id="async-two-async-dependencies-js-before">
    735 scriptEventLog.push( "async-two-async-dependencies: before inline" )
    736 //# sourceURL=async-two-async-dependencies-js-before
    737 </script>
    738 <script src='https://example.com/external.js?script_event_log=async-two-async-dependencies:%20script' id='async-two-async-dependencies-js' data-wp-strategy='async'></script>
    739 <script id="async-two-async-dependencies-js-after">
    740 scriptEventLog.push( "async-two-async-dependencies: after inline" )
    741 //# sourceURL=async-two-async-dependencies-js-after
    742 </script>
    743 HTML
    744                                 ,
     698                                <script id="async-no-dependency-js-before">
     699                                scriptEventLog.push( "async-no-dependency: before inline" )
     700                                //# sourceURL=async-no-dependency-js-before
     701                                </script>
     702                                <script src='https://example.com/external.js?script_event_log=async-no-dependency:%20script' id='async-no-dependency-js' data-wp-strategy='async'></script>
     703                                <script id="async-no-dependency-js-after">
     704                                scriptEventLog.push( "async-no-dependency: after inline" )
     705                                //# sourceURL=async-no-dependency-js-after
     706                                </script>
     707                                <script id="async-one-async-dependency-js-before">
     708                                scriptEventLog.push( "async-one-async-dependency: before inline" )
     709                                //# sourceURL=async-one-async-dependency-js-before
     710                                </script>
     711                                <script src='https://example.com/external.js?script_event_log=async-one-async-dependency:%20script' id='async-one-async-dependency-js' data-wp-strategy='async'></script>
     712                                <script id="async-one-async-dependency-js-after">
     713                                scriptEventLog.push( "async-one-async-dependency: after inline" )
     714                                //# sourceURL=async-one-async-dependency-js-after
     715                                </script>
     716                                <script id="async-two-async-dependencies-js-before">
     717                                scriptEventLog.push( "async-two-async-dependencies: before inline" )
     718                                //# sourceURL=async-two-async-dependencies-js-before
     719                                </script>
     720                                <script src='https://example.com/external.js?script_event_log=async-two-async-dependencies:%20script' id='async-two-async-dependencies-js' data-wp-strategy='async'></script>
     721                                <script id="async-two-async-dependencies-js-after">
     722                                scriptEventLog.push( "async-two-async-dependencies: after inline" )
     723                                //# sourceURL=async-two-async-dependencies-js-after
     724                                </script>
     725                                HTML,
    745726                        ),
    746727                        'async-with-blocking-dependency'               => array(
    … …  
    756737                                },
    757738                                'expected_markup' => <<<HTML
    758 <script id="async-with-blocking-dependent-js-before">
    759 scriptEventLog.push( "async-with-blocking-dependent: before inline" )
    760 //# sourceURL=async-with-blocking-dependent-js-before
    761 </script>
    762 <script src='https://example.com/external.js?script_event_log=async-with-blocking-dependent:%20script' id='async-with-blocking-dependent-js' data-wp-strategy='async'></script>
    763 <script id="async-with-blocking-dependent-js-after">
    764 scriptEventLog.push( "async-with-blocking-dependent: after inline" )
    765 //# sourceURL=async-with-blocking-dependent-js-after
    766 </script>
    767 <script id="blocking-dependent-of-async-js-before">
    768 scriptEventLog.push( "blocking-dependent-of-async: before inline" )
    769 //# sourceURL=blocking-dependent-of-async-js-before
    770 </script>
    771 <script src='https://example.com/external.js?script_event_log=blocking-dependent-of-async:%20script' id='blocking-dependent-of-async-js'></script>
    772 <script id="blocking-dependent-of-async-js-after">
    773 scriptEventLog.push( "blocking-dependent-of-async: after inline" )
    774 //# sourceURL=blocking-dependent-of-async-js-after
    775 </script>
    776 HTML
    777                                 ,
     739                                <script id="async-with-blocking-dependent-js-before">
     740                                scriptEventLog.push( "async-with-blocking-dependent: before inline" )
     741                                //# sourceURL=async-with-blocking-dependent-js-before
     742                                </script>
     743                                <script src='https://example.com/external.js?script_event_log=async-with-blocking-dependent:%20script' id='async-with-blocking-dependent-js' data-wp-strategy='async'></script>
     744                                <script id="async-with-blocking-dependent-js-after">
     745                                scriptEventLog.push( "async-with-blocking-dependent: after inline" )
     746                                //# sourceURL=async-with-blocking-dependent-js-after
     747                                </script>
     748                                <script id="blocking-dependent-of-async-js-before">
     749                                scriptEventLog.push( "blocking-dependent-of-async: before inline" )
     750                                //# sourceURL=blocking-dependent-of-async-js-before
     751                                </script>
     752                                <script src='https://example.com/external.js?script_event_log=blocking-dependent-of-async:%20script' id='blocking-dependent-of-async-js'></script>
     753                                <script id="blocking-dependent-of-async-js-after">
     754                                scriptEventLog.push( "blocking-dependent-of-async: after inline" )
     755                                //# sourceURL=blocking-dependent-of-async-js-after
     756                                </script>
     757                                HTML,
    778758                        ),
    779759                        'defer-with-async-dependency'                  => array(
    … …  
    789769                                },
    790770                                'expected_markup' => <<<HTML
    791 <script id="async-with-defer-dependent-js-before">
    792 scriptEventLog.push( "async-with-defer-dependent: before inline" )
    793 //# sourceURL=async-with-defer-dependent-js-before
    794 </script>
    795 <script src='https://example.com/external.js?script_event_log=async-with-defer-dependent:%20script' id='async-with-defer-dependent-js' data-wp-strategy='async'></script>
    796 <script id="async-with-defer-dependent-js-after">
    797 scriptEventLog.push( "async-with-defer-dependent: after inline" )
    798 //# sourceURL=async-with-defer-dependent-js-after
    799 </script>
    800 <script id="defer-dependent-of-async-js-before">
    801 scriptEventLog.push( "defer-dependent-of-async: before inline" )
    802 //# sourceURL=defer-dependent-of-async-js-before
    803 </script>
    804 <script src='https://example.com/external.js?script_event_log=defer-dependent-of-async:%20script' id='defer-dependent-of-async-js' data-wp-strategy='defer'></script>
    805 <script id="defer-dependent-of-async-js-after">
    806 scriptEventLog.push( "defer-dependent-of-async: after inline" )
    807 //# sourceURL=defer-dependent-of-async-js-after
    808 </script>
    809 HTML
    810                                 ,
     771                                <script id="async-with-defer-dependent-js-before">
     772                                scriptEventLog.push( "async-with-defer-dependent: before inline" )
     773                                //# sourceURL=async-with-defer-dependent-js-before
     774                                </script>
     775                                <script src='https://example.com/external.js?script_event_log=async-with-defer-dependent:%20script' id='async-with-defer-dependent-js' data-wp-strategy='async'></script>
     776                                <script id="async-with-defer-dependent-js-after">
     777                                scriptEventLog.push( "async-with-defer-dependent: after inline" )
     778                                //# sourceURL=async-with-defer-dependent-js-after
     779                                </script>
     780                                <script id="defer-dependent-of-async-js-before">
     781                                scriptEventLog.push( "defer-dependent-of-async: before inline" )
     782                                //# sourceURL=defer-dependent-of-async-js-before
     783                                </script>
     784                                <script src='https://example.com/external.js?script_event_log=defer-dependent-of-async:%20script' id='defer-dependent-of-async-js' data-wp-strategy='defer'></script>
     785                                <script id="defer-dependent-of-async-js-after">
     786                                scriptEventLog.push( "defer-dependent-of-async: after inline" )
     787                                //# sourceURL=defer-dependent-of-async-js-after
     788                                </script>
     789                                HTML,
    811790                        ),
    812791                        'blocking-bundle-of-none-with-inline-scripts-and-defer-dependent' => array(
    … …  
    825804                                },
    826805                                'expected_markup' => <<<HTML
    827 <script id="blocking-bundle-of-none-js-before">
    828 scriptEventLog.push( "blocking-bundle-of-none: before inline" )
    829 //# sourceURL=blocking-bundle-of-none-js-before
    830 </script>
    831 <script id="blocking-bundle-of-none-js-after">
    832 scriptEventLog.push( "blocking-bundle-of-none: after inline" )
    833 //# sourceURL=blocking-bundle-of-none-js-after
    834 </script>
    835 <script id="defer-dependent-of-blocking-bundle-of-none-js-before">
    836 scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: before inline" )
    837 //# sourceURL=defer-dependent-of-blocking-bundle-of-none-js-before
    838 </script>
    839 <script src='https://example.com/external.js?script_event_log=defer-dependent-of-blocking-bundle-of-none:%20script' id='defer-dependent-of-blocking-bundle-of-none-js' data-wp-strategy='defer'></script>
    840 <script id="defer-dependent-of-blocking-bundle-of-none-js-after">
    841 scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: after inline" )
    842 //# sourceURL=defer-dependent-of-blocking-bundle-of-none-js-after
    843 </script>
    844 HTML
    845                                 ,
     806                                <script id="blocking-bundle-of-none-js-before">
     807                                scriptEventLog.push( "blocking-bundle-of-none: before inline" )
     808                                //# sourceURL=blocking-bundle-of-none-js-before
     809                                </script>
     810                                <script id="blocking-bundle-of-none-js-after">
     811                                scriptEventLog.push( "blocking-bundle-of-none: after inline" )
     812                                //# sourceURL=blocking-bundle-of-none-js-after
     813                                </script>
     814                                <script id="defer-dependent-of-blocking-bundle-of-none-js-before">
     815                                scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: before inline" )
     816                                //# sourceURL=defer-dependent-of-blocking-bundle-of-none-js-before
     817                                </script>
     818                                <script src='https://example.com/external.js?script_event_log=defer-dependent-of-blocking-bundle-of-none:%20script' id='defer-dependent-of-blocking-bundle-of-none-js' data-wp-strategy='defer'></script>
     819                                <script id="defer-dependent-of-blocking-bundle-of-none-js-after">
     820                                scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-none: after inline" )
     821                                //# sourceURL=defer-dependent-of-blocking-bundle-of-none-js-after
     822                                </script>
     823                                HTML,
    846824                        ),
    847825                        'blocking-bundle-of-two-with-defer-dependent'  => array(
    … …  
    863841                                },
    864842                                'expected_markup' => <<<HTML
    865 <script id="blocking-bundle-member-one-js-before">
    866 scriptEventLog.push( "blocking-bundle-member-one: before inline" )
    867 //# sourceURL=blocking-bundle-member-one-js-before
    868 </script>
    869 <script src='https://example.com/external.js?script_event_log=blocking-bundle-member-one:%20script' id='blocking-bundle-member-one-js'></script>
    870 <script id="blocking-bundle-member-one-js-after">
    871 scriptEventLog.push( "blocking-bundle-member-one: after inline" )
    872 //# sourceURL=blocking-bundle-member-one-js-after
    873 </script>
    874 <script id="blocking-bundle-member-two-js-before">
    875 scriptEventLog.push( "blocking-bundle-member-two: before inline" )
    876 //# sourceURL=blocking-bundle-member-two-js-before
    877 </script>
    878 <script src='https://example.com/external.js?script_event_log=blocking-bundle-member-two:%20script' id='blocking-bundle-member-two-js'></script>
    879 <script id="blocking-bundle-member-two-js-after">
    880 scriptEventLog.push( "blocking-bundle-member-two: after inline" )
    881 //# sourceURL=blocking-bundle-member-two-js-after
    882 </script>
    883 <script id="defer-dependent-of-blocking-bundle-of-two-js-before">
    884 scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: before inline" )
    885 //# sourceURL=defer-dependent-of-blocking-bundle-of-two-js-before
    886 </script>
    887 <script src='https://example.com/external.js?script_event_log=defer-dependent-of-blocking-bundle-of-two:%20script' id='defer-dependent-of-blocking-bundle-of-two-js' data-wp-strategy='defer'></script>
    888 <script id="defer-dependent-of-blocking-bundle-of-two-js-after">
    889 scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: after inline" )
    890 //# sourceURL=defer-dependent-of-blocking-bundle-of-two-js-after
    891 </script>
    892 HTML
    893                                 ,
     843                                <script id="blocking-bundle-member-one-js-before">
     844                                scriptEventLog.push( "blocking-bundle-member-one: before inline" )
     845                                //# sourceURL=blocking-bundle-member-one-js-before
     846                                </script>
     847                                <script src='https://example.com/external.js?script_event_log=blocking-bundle-member-one:%20script' id='blocking-bundle-member-one-js'></script>
     848                                <script id="blocking-bundle-member-one-js-after">
     849                                scriptEventLog.push( "blocking-bundle-member-one: after inline" )
     850                                //# sourceURL=blocking-bundle-member-one-js-after
     851                                </script>
     852                                <script id="blocking-bundle-member-two-js-before">
     853                                scriptEventLog.push( "blocking-bundle-member-two: before inline" )
     854                                //# sourceURL=blocking-bundle-member-two-js-before
     855                                </script>
     856                                <script src='https://example.com/external.js?script_event_log=blocking-bundle-member-two:%20script' id='blocking-bundle-member-two-js'></script>
     857                                <script id="blocking-bundle-member-two-js-after">
     858                                scriptEventLog.push( "blocking-bundle-member-two: after inline" )
     859                                //# sourceURL=blocking-bundle-member-two-js-after
     860                                </script>
     861                                <script id="defer-dependent-of-blocking-bundle-of-two-js-before">
     862                                scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: before inline" )
     863                                //# sourceURL=defer-dependent-of-blocking-bundle-of-two-js-before
     864                                </script>
     865                                <script src='https://example.com/external.js?script_event_log=defer-dependent-of-blocking-bundle-of-two:%20script' id='defer-dependent-of-blocking-bundle-of-two-js' data-wp-strategy='defer'></script>
     866                                <script id="defer-dependent-of-blocking-bundle-of-two-js-after">
     867                                scriptEventLog.push( "defer-dependent-of-blocking-bundle-of-two: after inline" )
     868                                //# sourceURL=defer-dependent-of-blocking-bundle-of-two-js-after
     869                                </script>
     870                                HTML,
    894871                        ),
    895872                        'defer-bundle-of-none-with-inline-scripts-and-defer-dependents' => array(
    … …  
    910887                                },
    911888                                'expected_markup' => <<<HTML
    912 <script id="defer-bundle-of-none-js-before">
    913 scriptEventLog.push( "defer-bundle-of-none: before inline" )
    914 //# sourceURL=defer-bundle-of-none-js-before
    915 </script>
    916 <script id="defer-bundle-of-none-js-after">
    917 scriptEventLog.push( "defer-bundle-of-none: after inline" )
    918 //# sourceURL=defer-bundle-of-none-js-after
    919 </script>
    920 <script id="defer-dependent-of-defer-bundle-of-none-js-before">
    921 scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: before inline" )
    922 //# sourceURL=defer-dependent-of-defer-bundle-of-none-js-before
    923 </script>
    924 <script src='https://example.com/external.js?script_event_log=defer-dependent-of-defer-bundle-of-none:%20script' id='defer-dependent-of-defer-bundle-of-none-js' data-wp-strategy='defer'></script>
    925 <script id="defer-dependent-of-defer-bundle-of-none-js-after">
    926 scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: after inline" )
    927 //# sourceURL=defer-dependent-of-defer-bundle-of-none-js-after
    928 </script>
    929 HTML
    930                                 ,
     889                                <script id="defer-bundle-of-none-js-before">
     890                                scriptEventLog.push( "defer-bundle-of-none: before inline" )
     891                                //# sourceURL=defer-bundle-of-none-js-before
     892                                </script>
     893                                <script id="defer-bundle-of-none-js-after">
     894                                scriptEventLog.push( "defer-bundle-of-none: after inline" )
     895                                //# sourceURL=defer-bundle-of-none-js-after
     896                                </script>
     897                                <script id="defer-dependent-of-defer-bundle-of-none-js-before">
     898                                scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: before inline" )
     899                                //# sourceURL=defer-dependent-of-defer-bundle-of-none-js-before
     900                                </script>
     901                                <script src='https://example.com/external.js?script_event_log=defer-dependent-of-defer-bundle-of-none:%20script' id='defer-dependent-of-defer-bundle-of-none-js' data-wp-strategy='defer'></script>
     902                                <script id="defer-dependent-of-defer-bundle-of-none-js-after">
     903                                scriptEventLog.push( "defer-dependent-of-defer-bundle-of-none: after inline" )
     904                                //# sourceURL=defer-dependent-of-defer-bundle-of-none-js-after
     905                                </script>
     906                                HTML,
    931907                        ),
    932908                        'defer-dependent-with-blocking-and-defer-dependencies' => array(
    … …  
    945921                                },
    946922                                'expected_markup' => <<<HTML
    947 <script id="blocking-dependency-with-defer-following-dependency-js-before">
    948 scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: before inline" )
    949 //# sourceURL=blocking-dependency-with-defer-following-dependency-js-before
    950 </script>
    951 <script src='https://example.com/external.js?script_event_log=blocking-dependency-with-defer-following-dependency:%20script' id='blocking-dependency-with-defer-following-dependency-js'></script>
    952 <script id="blocking-dependency-with-defer-following-dependency-js-after">
    953 scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: after inline" )
    954 //# sourceURL=blocking-dependency-with-defer-following-dependency-js-after
    955 </script>
    956 <script id="defer-dependency-with-blocking-preceding-dependency-js-before">
    957 scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: before inline" )
    958 //# sourceURL=defer-dependency-with-blocking-preceding-dependency-js-before
    959 </script>
    960 <script src='https://example.com/external.js?script_event_log=defer-dependency-with-blocking-preceding-dependency:%20script' id='defer-dependency-with-blocking-preceding-dependency-js' data-wp-strategy='defer'></script>
    961 <script id="defer-dependency-with-blocking-preceding-dependency-js-after">
    962 scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: after inline" )
    963 //# sourceURL=defer-dependency-with-blocking-preceding-dependency-js-after
    964 </script>
    965 <script id="defer-dependent-of-blocking-and-defer-dependencies-js-before">
    966 scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: before inline" )
    967 //# sourceURL=defer-dependent-of-blocking-and-defer-dependencies-js-before
    968 </script>
    969 <script src='https://example.com/external.js?script_event_log=defer-dependent-of-blocking-and-defer-dependencies:%20script' id='defer-dependent-of-blocking-and-defer-dependencies-js' data-wp-strategy='defer'></script>
    970 <script id="defer-dependent-of-blocking-and-defer-dependencies-js-after">
    971 scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: after inline" )
    972 //# sourceURL=defer-dependent-of-blocking-and-defer-dependencies-js-after
    973 </script>
    974 HTML
    975                                 ,
     923                                <script id="blocking-dependency-with-defer-following-dependency-js-before">
     924                                scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: before inline" )
     925                                //# sourceURL=blocking-dependency-with-defer-following-dependency-js-before
     926                                </script>
     927                                <script src='https://example.com/external.js?script_event_log=blocking-dependency-with-defer-following-dependency:%20script' id='blocking-dependency-with-defer-following-dependency-js'></script>
     928                                <script id="blocking-dependency-with-defer-following-dependency-js-after">
     929                                scriptEventLog.push( "blocking-dependency-with-defer-following-dependency: after inline" )
     930                                //# sourceURL=blocking-dependency-with-defer-following-dependency-js-after
     931                                </script>
     932                                <script id="defer-dependency-with-blocking-preceding-dependency-js-before">
     933                                scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: before inline" )
     934                                //# sourceURL=defer-dependency-with-blocking-preceding-dependency-js-before
     935                                </script>
     936                                <script src='https://example.com/external.js?script_event_log=defer-dependency-with-blocking-preceding-dependency:%20script' id='defer-dependency-with-blocking-preceding-dependency-js' data-wp-strategy='defer'></script>
     937                                <script id="defer-dependency-with-blocking-preceding-dependency-js-after">
     938                                scriptEventLog.push( "defer-dependency-with-blocking-preceding-dependency: after inline" )
     939                                //# sourceURL=defer-dependency-with-blocking-preceding-dependency-js-after
     940                                </script>
     941                                <script id="defer-dependent-of-blocking-and-defer-dependencies-js-before">
     942                                scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: before inline" )
     943                                //# sourceURL=defer-dependent-of-blocking-and-defer-dependencies-js-before
     944                                </script>
     945                                <script src='https://example.com/external.js?script_event_log=defer-dependent-of-blocking-and-defer-dependencies:%20script' id='defer-dependent-of-blocking-and-defer-dependencies-js' data-wp-strategy='defer'></script>
     946                                <script id="defer-dependent-of-blocking-and-defer-dependencies-js-after">
     947                                scriptEventLog.push( "defer-dependent-of-blocking-and-defer-dependencies: after inline" )
     948                                //# sourceURL=defer-dependent-of-blocking-and-defer-dependencies-js-after
     949                                </script>
     950                                HTML,
    976951                        ),
    977952                        'defer-dependent-with-defer-and-blocking-dependencies' => array(
    … …  
    990965                                },
    991966                                'expected_markup' => <<<HTML
    992 <script id="defer-dependency-with-blocking-following-dependency-js-before">
    993 scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: before inline" )
    994 //# sourceURL=defer-dependency-with-blocking-following-dependency-js-before
    995 </script>
    996 <script src='https://example.com/external.js?script_event_log=defer-dependency-with-blocking-following-dependency:%20script' id='defer-dependency-with-blocking-following-dependency-js' data-wp-strategy='defer'></script>
    997 <script id="defer-dependency-with-blocking-following-dependency-js-after">
    998 scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: after inline" )
    999 //# sourceURL=defer-dependency-with-blocking-following-dependency-js-after
    1000 </script>
    1001 <script id="blocking-dependency-with-defer-preceding-dependency-js-before">
    1002 scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: before inline" )
    1003 //# sourceURL=blocking-dependency-with-defer-preceding-dependency-js-before
    1004 </script>
    1005 <script src='https://example.com/external.js?script_event_log=blocking-dependency-with-defer-preceding-dependency:%20script' id='blocking-dependency-with-defer-preceding-dependency-js'></script>
    1006 <script id="blocking-dependency-with-defer-preceding-dependency-js-after">
    1007 scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: after inline" )
    1008 //# sourceURL=blocking-dependency-with-defer-preceding-dependency-js-after
    1009 </script>
    1010 <script id="defer-dependent-of-defer-and-blocking-dependencies-js-before">
    1011 scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: before inline" )
    1012 //# sourceURL=defer-dependent-of-defer-and-blocking-dependencies-js-before
    1013 </script>
    1014 <script src='https://example.com/external.js?script_event_log=defer-dependent-of-defer-and-blocking-dependencies:%20script' id='defer-dependent-of-defer-and-blocking-dependencies-js' data-wp-strategy='defer'></script>
    1015 <script id="defer-dependent-of-defer-and-blocking-dependencies-js-after">
    1016 scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: after inline" )
    1017 //# sourceURL=defer-dependent-of-defer-and-blocking-dependencies-js-after
    1018 </script>
    1019 HTML
    1020                                 ,
     967                                <script id="defer-dependency-with-blocking-following-dependency-js-before">
     968                                scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: before inline" )
     969                                //# sourceURL=defer-dependency-with-blocking-following-dependency-js-before
     970                                </script>
     971                                <script src='https://example.com/external.js?script_event_log=defer-dependency-with-blocking-following-dependency:%20script' id='defer-dependency-with-blocking-following-dependency-js' data-wp-strategy='defer'></script>
     972                                <script id="defer-dependency-with-blocking-following-dependency-js-after">
     973                                scriptEventLog.push( "defer-dependency-with-blocking-following-dependency: after inline" )
     974                                //# sourceURL=defer-dependency-with-blocking-following-dependency-js-after
     975                                </script>
     976                                <script id="blocking-dependency-with-defer-preceding-dependency-js-before">
     977                                scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: before inline" )
     978                                //# sourceURL=blocking-dependency-with-defer-preceding-dependency-js-before
     979                                </script>
     980                                <script src='https://example.com/external.js?script_event_log=blocking-dependency-with-defer-preceding-dependency:%20script' id='blocking-dependency-with-defer-preceding-dependency-js'></script>
     981                                <script id="blocking-dependency-with-defer-preceding-dependency-js-after">
     982                                scriptEventLog.push( "blocking-dependency-with-defer-preceding-dependency: after inline" )
     983                                //# sourceURL=blocking-dependency-with-defer-preceding-dependency-js-after
     984                                </script>
     985                                <script id="defer-dependent-of-defer-and-blocking-dependencies-js-before">
     986                                scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: before inline" )
     987                                //# sourceURL=defer-dependent-of-defer-and-blocking-dependencies-js-before
     988                                </script>
     989                                <script src='https://example.com/external.js?script_event_log=defer-dependent-of-defer-and-blocking-dependencies:%20script' id='defer-dependent-of-defer-and-blocking-dependencies-js' data-wp-strategy='defer'></script>
     990                                <script id="defer-dependent-of-defer-and-blocking-dependencies-js-after">
     991                                scriptEventLog.push( "defer-dependent-of-defer-and-blocking-dependencies: after inline" )
     992                                //# sourceURL=defer-dependent-of-defer-and-blocking-dependencies-js-after
     993                                </script>
     994                                HTML,
    1021995                        ),
    1022996                        'async-with-defer-dependency'                  => array(
    … …  
    10321006                                },
    10331007                                'expected_markup' => <<<HTML
    1034 <script id="defer-with-async-dependent-js-before">
    1035 scriptEventLog.push( "defer-with-async-dependent: before inline" )
    1036 //# sourceURL=defer-with-async-dependent-js-before
    1037 </script>
    1038 <script src='https://example.com/external.js?script_event_log=defer-with-async-dependent:%20script' id='defer-with-async-dependent-js' data-wp-strategy='defer'></script>
    1039 <script id="defer-with-async-dependent-js-after">
    1040 scriptEventLog.push( "defer-with-async-dependent: after inline" )
    1041 //# sourceURL=defer-with-async-dependent-js-after
    1042 </script>
    1043 <script id="async-dependent-of-defer-js-before">
    1044 scriptEventLog.push( "async-dependent-of-defer: before inline" )
    1045 //# sourceURL=async-dependent-of-defer-js-before
    1046 </script>
    1047 <script src='https://example.com/external.js?script_event_log=async-dependent-of-defer:%20script' id='async-dependent-of-defer-js' data-wp-strategy='async'></script>
    1048 <script id="async-dependent-of-defer-js-after">
    1049 scriptEventLog.push( "async-dependent-of-defer: after inline" )
    1050 //# sourceURL=async-dependent-of-defer-js-after
    1051 </script>
    1052 HTML
    1053                                 ,
     1008                                <script id="defer-with-async-dependent-js-before">
     1009                                scriptEventLog.push( "defer-with-async-dependent: before inline" )
     1010                                //# sourceURL=defer-with-async-dependent-js-before
     1011                                </script>
     1012                                <script src='https://example.com/external.js?script_event_log=defer-with-async-dependent:%20script' id='defer-with-async-dependent-js' data-wp-strategy='defer'></script>
     1013                                <script id="defer-with-async-dependent-js-after">
     1014                                scriptEventLog.push( "defer-with-async-dependent: after inline" )
     1015                                //# sourceURL=defer-with-async-dependent-js-after
     1016                                </script>
     1017                                <script id="async-dependent-of-defer-js-before">
     1018                                scriptEventLog.push( "async-dependent-of-defer: before inline" )
     1019                                //# sourceURL=async-dependent-of-defer-js-before
     1020                                </script>
     1021                                <script src='https://example.com/external.js?script_event_log=async-dependent-of-defer:%20script' id='async-dependent-of-defer-js' data-wp-strategy='async'></script>
     1022                                <script id="async-dependent-of-defer-js-after">
     1023                                scriptEventLog.push( "async-dependent-of-defer: after inline" )
     1024                                //# sourceURL=async-dependent-of-defer-js-after
     1025                                </script>
     1026                                HTML,
    10541027                        ),
    10551028                        'defer-with-before-inline-script'              => array(
    … …  
    10611034                                },
    10621035                                'expected_markup' => <<<HTML
    1063 <script id="defer-with-before-inline-js-before">
    1064 scriptEventLog.push( "defer-with-before-inline: before inline" )
    1065 //# sourceURL=defer-with-before-inline-js-before
    1066 </script>
    1067 <script src='https://example.com/external.js?script_event_log=defer-with-before-inline:%20script' id='defer-with-before-inline-js' defer data-wp-strategy='defer'></script>
    1068 HTML
    1069                                 ,
     1036                                <script id="defer-with-before-inline-js-before">
     1037                                scriptEventLog.push( "defer-with-before-inline: before inline" )
     1038                                //# sourceURL=defer-with-before-inline-js-before
     1039                                </script>
     1040                                <script src='https://example.com/external.js?script_event_log=defer-with-before-inline:%20script' id='defer-with-before-inline-js' defer data-wp-strategy='defer'></script>
     1041                                HTML,
    10701042                        ),
    10711043                        'defer-with-after-inline-script'               => array(
    … …  
    10771049                                },
    10781050                                'expected_markup' => <<<HTML
    1079 <script src='https://example.com/external.js?script_event_log=defer-with-after-inline:%20script' id='defer-with-after-inline-js' data-wp-strategy='defer'></script>
    1080 <script id="defer-with-after-inline-js-after">
    1081 scriptEventLog.push( "defer-with-after-inline: after inline" )
    1082 //# sourceURL=defer-with-after-inline-js-after
    1083 </script>
    1084 HTML
    1085                                 ,
     1051                                <script src='https://example.com/external.js?script_event_log=defer-with-after-inline:%20script' id='defer-with-after-inline-js' data-wp-strategy='defer'></script>
     1052                                <script id="defer-with-after-inline-js-after">
     1053                                scriptEventLog.push( "defer-with-after-inline: after inline" )
     1054                                //# sourceURL=defer-with-after-inline-js-after
     1055                                </script>
     1056                                HTML,
    10861057                        ),
    10871058                        'jquery-deferred'                              => array(
    … …  
    10961067                                },
    10971068                                'expected_markup' => <<<HTML
    1098 <script src='http://$wp_tests_domain/wp-includes/js/jquery/jquery.js' id='jquery-core-js' defer data-wp-strategy='defer'></script>
    1099 <script src='http://$wp_tests_domain/wp-includes/js/jquery/jquery-migrate.js' id='jquery-migrate-js' defer data-wp-strategy='defer'></script>
    1100 <script src='https://example.com/theme-functions.js' id='theme-functions-js' defer data-wp-strategy='defer'></script>
    1101 HTML
    1102                                 ,
     1069                                <script src='http://$wp_tests_domain/wp-includes/js/jquery/jquery.js' id='jquery-core-js' defer data-wp-strategy='defer'></script>
     1070                                <script src='http://$wp_tests_domain/wp-includes/js/jquery/jquery-migrate.js' id='jquery-migrate-js' defer data-wp-strategy='defer'></script>
     1071                                <script src='https://example.com/theme-functions.js' id='theme-functions-js' defer data-wp-strategy='defer'></script>
     1072                                HTML,
    11031073                        ),
    11041074                        'nested-aliases'                               => array(
    … …  
    11211091                                },
    11221092                                'expected_markup' => <<<HTML
    1123 <script src='https://example.com/external.js?script_event_log=inner-bundle-member-one:%20script' id='inner-bundle-member-one-js' data-wp-strategy='defer'></script>
    1124 <script src='https://example.com/external.js?script_event_log=inner-bundle-member-two:%20script' id='inner-bundle-member-two-js' data-wp-strategy='defer'></script>
    1125 <script src='https://example.com/external.js?script_event_log=outer-bundle-leaf-member:%20script' id='outer-bundle-leaf-member-js'></script>
    1126 <script id="defer-dependent-of-nested-aliases-js-before">
    1127 scriptEventLog.push( "defer-dependent-of-nested-aliases: before inline" )
    1128 //# sourceURL=defer-dependent-of-nested-aliases-js-before
    1129 </script>
    1130 <script src='https://example.com/external.js?script_event_log=defer-dependent-of-nested-aliases:%20script' id='defer-dependent-of-nested-aliases-js' data-wp-strategy='defer'></script>
    1131 <script id="defer-dependent-of-nested-aliases-js-after">
    1132 scriptEventLog.push( "defer-dependent-of-nested-aliases: after inline" )
    1133 //# sourceURL=defer-dependent-of-nested-aliases-js-after
    1134 </script>
    1135 HTML
    1136                                 ,
     1093                                <script src='https://example.com/external.js?script_event_log=inner-bundle-member-one:%20script' id='inner-bundle-member-one-js' data-wp-strategy='defer'></script>
     1094                                <script src='https://example.com/external.js?script_event_log=inner-bundle-member-two:%20script' id='inner-bundle-member-two-js' data-wp-strategy='defer'></script>
     1095                                <script src='https://example.com/external.js?script_event_log=outer-bundle-leaf-member:%20script' id='outer-bundle-leaf-member-js'></script>
     1096                                <script id="defer-dependent-of-nested-aliases-js-before">
     1097                                scriptEventLog.push( "defer-dependent-of-nested-aliases: before inline" )
     1098                                //# sourceURL=defer-dependent-of-nested-aliases-js-before
     1099                                </script>
     1100                                <script src='https://example.com/external.js?script_event_log=defer-dependent-of-nested-aliases:%20script' id='defer-dependent-of-nested-aliases-js' data-wp-strategy='defer'></script>
     1101                                <script id="defer-dependent-of-nested-aliases-js-after">
     1102                                scriptEventLog.push( "defer-dependent-of-nested-aliases: after inline" )
     1103                                //# sourceURL=defer-dependent-of-nested-aliases-js-after
     1104                                </script>
     1105                                HTML,
    11371106                        ),
    11381107
    … …  
    11501119                                },
    11511120                                'expected_markup' => <<<HTML
    1152 <script src='https://example.com/external.js?script_event_log=async1:%20script' id='async1-js' defer data-wp-strategy='async'></script>
    1153 <script src='https://example.com/external.js?script_event_log=async2:%20script' id='async2-js' defer data-wp-strategy='async'></script>
    1154 <script src='https://example.com/external.js?script_event_log=defer-dependent-of-async-aliases:%20script' id='defer-dependent-of-async-aliases-js' defer data-wp-strategy='defer'></script>
    1155 HTML
    1156                                 ,
     1121                                <script src='https://example.com/external.js?script_event_log=async1:%20script' id='async1-js' defer data-wp-strategy='async'></script>
     1122                                <script src='https://example.com/external.js?script_event_log=async2:%20script' id='async2-js' defer data-wp-strategy='async'></script>
     1123                                <script src='https://example.com/external.js?script_event_log=defer-dependent-of-async-aliases:%20script' id='defer-dependent-of-async-aliases-js' defer data-wp-strategy='defer'></script>
     1124                                HTML,
    11571125                        ),
    11581126                );
    … …  
    17361704                $actual   = get_echo( 'wp_print_scripts' );
    17371705                $expected = <<<'HTML'
    1738 <script src="/z.js" id="z-js" fetchpriority="high" data-wp-fetchpriority="auto"></script>
    1739 <script src="/d.js" id="d-js" fetchpriority="high"></script>
    1740 <script src="/e.js" id="e-js"></script>
    1741 <script src="/c.js" id="c-js"></script>
    1742 <script src="/b.js" id="b-js"></script>
    1743 <script src="/a.js" id="a-js" fetchpriority="low"></script>
    1744 <script src="/y.js" id="y-js" fetchpriority="high" data-wp-fetchpriority="auto"></script>
    1745 <script src="/x.js" id="x-js" fetchpriority="high"></script>
    1746 
    1747 HTML;
     1706                <script src="/z.js" id="z-js" fetchpriority="high" data-wp-fetchpriority="auto"></script>
     1707                <script src="/d.js" id="d-js" fetchpriority="high"></script>
     1708                <script src="/e.js" id="e-js"></script>
     1709                <script src="/c.js" id="c-js"></script>
     1710                <script src="/b.js" id="b-js"></script>
     1711                <script src="/a.js" id="a-js" fetchpriority="low"></script>
     1712                <script src="/y.js" id="y-js" fetchpriority="high" data-wp-fetchpriority="auto"></script>
     1713                <script src="/x.js" id="x-js" fetchpriority="high"></script>
     1714
     1715                HTML;
    17481716                $this->assertEqualHTML( $expected, $actual, '<body>', "Snapshot:\n$actual" );
    17491717        }
    … …  
    21642132
    21652133        /**
    2166          * Tests that scripts registered with a deferred strategy are not included in the script concat loading query.
    2167          *
    2168          * @ticket 12009
    2169          *
    2170          * @covers WP_Scripts::do_item
    2171          * @covers ::wp_enqueue_script
    2172          * @covers ::wp_register_script
    2173          *
    2174          * @global WP_Scripts $wp_scripts
    2175          * @global bool       $concatenate_scripts
    2176          * @global string     $wp_version
    2177          */
    2178         public function test_concatenate_with_defer_strategy() {
    2179                 global $wp_scripts, $concatenate_scripts, $wp_version;
    2180 
    2181                 $concatenate_scripts = true;
    2182 
    2183                 $wp_scripts->do_concat    = true;
    2184                 $wp_scripts->default_dirs = array( $this->default_scripts_dir );
    2185 
    2186                 wp_register_script( 'one-concat-dep', $this->default_scripts_dir . 'script.js' );
    2187                 wp_register_script( 'two-concat-dep', $this->default_scripts_dir . 'script.js' );
    2188                 wp_register_script( 'three-concat-dep', $this->default_scripts_dir . 'script.js' );
    2189                 wp_enqueue_script( 'main-defer-script', '/main-script.js', array( 'one-concat-dep', 'two-concat-dep', 'three-concat-dep' ), null, array( 'strategy' => 'defer' ) );
    2190 
    2191                 wp_print_scripts();
    2192                 $print_scripts = get_echo( '_print_scripts' );
    2193 
    2194                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=one-concat-dep,two-concat-dep,three-concat-dep&amp;ver={$wp_version}'></script>\n";
    2195                 $expected .= "<script src='/main-script.js' id='main-defer-script-js' defer data-wp-strategy='defer'></script>\n";
    2196 
    2197                 $this->assertEqualHTML( $expected, $print_scripts, '<body>', 'Scripts are being incorrectly concatenated when a main script is registered with a "defer" loading strategy. Deferred scripts should not be part of the script concat loading query.' );
    2198         }
    2199 
    2200         /**
    2201          * Test script concatenation with `async` main script.
    2202          *
    2203          * @ticket 12009
    2204          *
    2205          * @covers WP_Scripts::do_item
    2206          * @covers ::wp_enqueue_script
    2207          * @covers ::wp_register_script
    2208          *
    2209          * @global WP_Scripts $wp_scripts
    2210          * @global bool       $concatenate_scripts
    2211          * @global string     $wp_version
    2212          */
    2213         public function test_concatenate_with_async_strategy() {
    2214                 global $wp_scripts, $concatenate_scripts, $wp_version;
    2215 
    2216                 $concatenate_scripts = true;
    2217 
    2218                 $wp_scripts->do_concat    = true;
    2219                 $wp_scripts->default_dirs = array( $this->default_scripts_dir );
    2220 
    2221                 wp_enqueue_script( 'one-concat-dep-1', $this->default_scripts_dir . 'script.js' );
    2222                 wp_enqueue_script( 'two-concat-dep-1', $this->default_scripts_dir . 'script.js' );
    2223                 wp_enqueue_script( 'three-concat-dep-1', $this->default_scripts_dir . 'script.js' );
    2224                 wp_enqueue_script( 'main-async-script-1', '/main-script.js', array(), null, array( 'strategy' => 'async' ) );
    2225 
    2226                 wp_print_scripts();
    2227                 $print_scripts = get_echo( '_print_scripts' );
    2228 
    2229                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=one-concat-dep-1,two-concat-dep-1,three-concat-dep-1&amp;ver={$wp_version}'></script>\n";
    2230                 $expected .= "<script src='/main-script.js' id='main-async-script-1-js' async data-wp-strategy='async'></script>\n";
    2231 
    2232                 $this->assertEqualHTML( $expected, $print_scripts, '<body>', 'Scripts are being incorrectly concatenated when a main script is registered with an "async" loading strategy. Async scripts should not be part of the script concat loading query.' );
    2233         }
    2234 
    2235         /**
    2236          * Tests that script concatenation remains correct when a main script is registered as deferred after other blocking
    2237          * scripts are registered.
    2238          *
    2239          * @ticket 12009
    2240          *
    2241          * @covers WP_Scripts::do_item
    2242          * @covers ::wp_enqueue_script
    2243          * @covers ::wp_register_script
    2244          *
    2245          * @global WP_Scripts $wp_scripts
    2246          * @global bool       $concatenate_scripts
    2247          * @global string     $wp_version
    2248          */
    2249         public function test_concatenate_with_blocking_script_before_and_after_script_with_defer_strategy() {
    2250                 global $wp_scripts, $concatenate_scripts, $wp_version;
    2251 
    2252                 $concatenate_scripts = true;
    2253 
    2254                 $wp_scripts->do_concat    = true;
    2255                 $wp_scripts->default_dirs = array( $this->default_scripts_dir );
    2256 
    2257                 wp_enqueue_script( 'one-concat-dep-2', $this->default_scripts_dir . 'script.js' );
    2258                 wp_enqueue_script( 'two-concat-dep-2', $this->default_scripts_dir . 'script.js' );
    2259                 wp_enqueue_script( 'three-concat-dep-2', $this->default_scripts_dir . 'script.js' );
    2260                 wp_enqueue_script( 'deferred-script-2', '/main-script.js', array(), null, array( 'strategy' => 'defer' ) );
    2261                 wp_enqueue_script( 'four-concat-dep-2', $this->default_scripts_dir . 'script.js' );
    2262                 wp_enqueue_script( 'five-concat-dep-2', $this->default_scripts_dir . 'script.js' );
    2263                 wp_enqueue_script( 'six-concat-dep-2', $this->default_scripts_dir . 'script.js' );
    2264 
    2265                 wp_print_scripts();
    2266                 $print_scripts = get_echo( '_print_scripts' );
    2267 
    2268                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=one-concat-dep-2,two-concat-dep-2,three-concat-dep-2,four-concat-dep-2,five-concat-dep-2,six-concat-dep-2&amp;ver={$wp_version}'></script>\n";
    2269                 $expected .= "<script src='/main-script.js' id='deferred-script-2-js' defer data-wp-strategy='defer'></script>\n";
    2270 
    2271                 $this->assertEqualHTML( $expected, $print_scripts, '<body>', 'Scripts are being incorrectly concatenated when a main script is registered as deferred after other blocking scripts are registered. Deferred scripts should not be part of the script concat loader query string. ' );
    2272         }
    2273 
    2274         /**
    22752134         * Test the different protocol references in wp_enqueue_script
    22762135         *
    … …  
    23182177
    23192178        /**
    2320          * Test script concatenation.
     2179         * Tests that the deprecated `do_concat` property no longer holds back the markup of scripts.
     2180         *
     2181         * @ticket 57548
     2182         *
     2183         * @covers WP_Scripts::do_item
    23212184         *
    23222185         * @global WP_Scripts $wp_scripts
    2323          * @global string $wp_version
    2324          */
    2325         public function test_script_concatenation() {
     2186         * @global string     $wp_version
     2187         */
     2188        public function test_do_concat_is_ignored(): void {
    23262189                global $wp_scripts, $wp_version;
    23272190
    2328                 $wp_scripts->do_concat    = true;
    2329                 $wp_scripts->default_dirs = array( $this->default_scripts_dir );
    2330 
    2331                 wp_enqueue_script( 'one', $this->default_scripts_dir . 'script.js' );
    2332                 wp_enqueue_script( 'two', $this->default_scripts_dir . 'script.js' );
    2333                 wp_enqueue_script( 'three', $this->default_scripts_dir . 'script.js' );
    2334 
    2335                 wp_print_scripts();
    2336                 $print_scripts = get_echo( '_print_scripts' );
    2337 
    2338                 $expected = "<script src=\"/wp-admin/load-scripts.php?load%5Bchunk_0%5D=one,two,three&#038;ver={$wp_version}\"></script>\n";
    2339 
    2340                 $this->assertEqualHTML( $expected, $print_scripts );
     2191                // The deprecated property is set as plugins may still do, to verify that it no longer has any effect.
     2192                $wp_scripts->do_concat = true;
     2193
     2194                // A plain blocking script comes first, since anything with inline scripts stopped concatenation.
     2195                wp_enqueue_script( 'zero', '/wp-includes/js/zero.js' );
     2196                wp_enqueue_script( 'one', '/wp-includes/js/one.js' );
     2197                wp_localize_script( 'one', 'one', array( 'key' => 'val' ) );
     2198                wp_add_inline_script( 'one', 'console.log("before one");', 'before' );
     2199                wp_register_script( 'alias', false, array( 'one' ) );
     2200                wp_add_inline_script( 'alias', 'console.log("after alias");' );
     2201                wp_enqueue_script( 'two', '/plugins/two.js', array( 'alias' ), null, array( 'strategy' => 'defer' ) );
     2202
     2203                $expected = <<<HTML
     2204                <script src="/wp-includes/js/zero.js?ver={$wp_version}" id="zero-js"></script>
     2205                <script id="one-js-extra">
     2206                var one = {"key":"val"};
     2207                //# sourceURL=one-js-extra
     2208                </script>
     2209                <script id="one-js-before">
     2210                console.log("before one");
     2211                //# sourceURL=one-js-before
     2212                </script>
     2213                <script src="/wp-includes/js/one.js?ver={$wp_version}" id="one-js"></script>
     2214                <script id="alias-js-after">
     2215                console.log("after alias");
     2216                //# sourceURL=alias-js-after
     2217                </script>
     2218                <script src="/plugins/two.js" id="two-js" defer data-wp-strategy="defer"></script>
     2219
     2220                HTML;
     2221
     2222                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ), '<body>', 'Expected each script to be printed right away.' );
     2223                $this->assertSame( '', $wp_scripts->print_html, 'Expected nothing to be held in print_html.' );
     2224        }
     2225
     2226        /**
     2227         * Tests that WP_Scripts::in_default_dir() is deprecated but still works.
     2228         *
     2229         * @ticket 57548
     2230         *
     2231         * @covers WP_Scripts::in_default_dir
     2232         *
     2233         * @expectedDeprecated WP_Scripts::in_default_dir
     2234         */
     2235        public function test_in_default_dir_is_deprecated(): void {
     2236                $wp_scripts               = wp_scripts();
     2237                $wp_scripts->default_dirs = array( '/wp-includes/js/' );
     2238
     2239                $this->assertTrue( $wp_scripts->in_default_dir( '/wp-includes/js/file' ) );
     2240        }
     2241
     2242        /**
     2243         * Tests that extra data which is not a string is not printed.
     2244         *
     2245         * @ticket 57548
     2246         *
     2247         * @covers WP_Scripts::print_extra_script
     2248         */
     2249        public function test_print_extra_script_skips_non_string_data(): void {
     2250                wp_register_script( 'test-example', '/example.js', array(), null );
     2251                wp_script_add_data( 'test-example', 'data', array( 'foo' => 'bar' ) );
     2252
     2253                $this->assertNull( wp_scripts()->print_extra_script( 'test-example', false ), 'Expected no extra script to be returned.' );
     2254                $this->assertEqualHTML( "<script src='/example.js' id='test-example-js'></script>\n", get_echo( 'wp_print_scripts', array( 'test-example' ) ), '<body>', 'Expected only the script tag to be printed.' );
     2255        }
     2256
     2257        /**
     2258         * Tests that the deprecated filters for printing scripts no longer keep them from being printed.
     2259         *
     2260         * @ticket 57548
     2261         *
     2262         * @covers ::print_head_scripts
     2263         * @covers ::print_footer_scripts
     2264         *
     2265         * @expectedDeprecated print_head_scripts
     2266         * @expectedDeprecated print_footer_scripts
     2267         */
     2268        public function test_print_scripts_filters_are_deprecated(): void {
     2269                add_filter( 'print_head_scripts', '__return_false' );
     2270                add_filter( 'print_footer_scripts', '__return_false' );
     2271
     2272                wp_enqueue_script( 'head', '/head.js', array(), null );
     2273                wp_enqueue_script( 'footer', '/footer.js', array(), null, array( 'in_footer' => true ) );
     2274
     2275                $this->assertEqualHTML( "<script src='/head.js' id='head-js'></script>\n", get_echo( 'print_head_scripts' ), '<body>', 'Expected the head scripts to be printed.' );
     2276                $this->assertEqualHTML( "<script src='/footer.js' id='footer-js'></script>\n", get_echo( 'print_footer_scripts' ), '<body>', 'Expected the footer scripts to be printed.' );
    23412277        }
    23422278
    … …  
    25872523
    25882524                $expected  = <<<HTML
    2589 <script id='test-example-js-before'>
    2590 console.log("before");
    2591 //# sourceURL=test-example-js-before
    2592 </script>
    2593 
    2594 HTML;
     2525                <script id='test-example-js-before'>
     2526                console.log("before");
     2527                //# sourceURL=test-example-js-before
     2528                </script>
     2529
     2530                HTML;
    25952531                $expected .= "<script src='http://example.com' id='test-example-js'></script>\n";
    25962532
    … …  
    26072543                $expected  = "<script src='http://example.com' id='test-example-js'></script>\n";
    26082544                $expected .= <<<HTML
    2609 <script id='test-example-js-after'>
    2610 console.log("after");
    2611 //# sourceURL=test-example-js-after
    2612 </script>
    2613 
    2614 HTML;
     2545                <script id='test-example-js-after'>
     2546                console.log("after");
     2547                //# sourceURL=test-example-js-after
     2548                </script>
     2549
     2550                HTML;
    26152551
    26162552                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    … …  
    27032639                $expected .= "<script src='http://example.com' id='test-example-js'></script>\n";
    27042640                $expected .= "<script id='test-example-js-after'>\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n</script>\n";
    2705 
    2706                 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    2707         }
    2708 
    2709         /**
    2710          * @ticket 14853
    2711          */
    2712         public function test_wp_add_inline_script_before_with_concat() {
    2713                 global $wp_scripts, $wp_version;
    2714 
    2715                 $wp_scripts->do_concat    = true;
    2716                 $wp_scripts->default_dirs = array( $this->default_scripts_dir );
    2717 
    2718                 wp_enqueue_script( 'one', $this->default_scripts_dir . 'one.js' );
    2719                 wp_enqueue_script( 'two', $this->default_scripts_dir . 'two.js' );
    2720                 wp_enqueue_script( 'three', $this->default_scripts_dir . 'three.js' );
    2721 
    2722                 wp_add_inline_script( 'one', 'console.log("before one");', 'before' );
    2723                 wp_add_inline_script( 'two', 'console.log("before two");', 'before' );
    2724 
    2725                 $expected  = "<script id='one-js-before'>\nconsole.log(\"before one\");\n//# sourceURL=one-js-before\n</script>\n";
    2726                 $expected .= "<script src='{$this->default_scripts_dir}one.js?ver={$wp_version}' id='one-js'></script>\n";
    2727                 $expected .= "<script id='two-js-before'>\nconsole.log(\"before two\");\n//# sourceURL=two-js-before\n</script>\n";
    2728                 $expected .= "<script src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
    2729                 $expected .= "<script src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n";
    2730 
    2731                 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    2732         }
    2733 
    2734         /**
    2735          * @ticket 14853
    2736          */
    2737         public function test_wp_add_inline_script_before_with_concat2() {
    2738                 global $wp_scripts, $wp_version;
    2739 
    2740                 $wp_scripts->do_concat    = true;
    2741                 $wp_scripts->default_dirs = array( $this->default_scripts_dir );
    2742 
    2743                 wp_enqueue_script( 'one', $this->default_scripts_dir . 'one.js' );
    2744                 wp_enqueue_script( 'two', $this->default_scripts_dir . 'two.js' );
    2745                 wp_enqueue_script( 'three', $this->default_scripts_dir . 'three.js' );
    2746 
    2747                 wp_add_inline_script( 'one', 'console.log("before one");', 'before' );
    2748 
    2749                 $expected  = "<script id='one-js-before'>\nconsole.log(\"before one\");\n//# sourceURL=one-js-before\n</script>\n";
    2750                 $expected .= "<script src='{$this->default_scripts_dir}one.js?ver={$wp_version}' id='one-js'></script>\n";
    2751                 $expected .= "<script src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
    2752                 $expected .= "<script src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n";
    2753 
    2754                 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    2755         }
    2756 
    2757         /**
    2758          * @ticket 14853
    2759          *
    2760          * @global WP_Scripts $wp_scripts
    2761          * @global string     $wp_version
    2762          */
    2763         public function test_wp_add_inline_script_after_with_concat() {
    2764                 global $wp_scripts, $wp_version;
    2765 
    2766                 $wp_scripts->do_concat    = true;
    2767                 $wp_scripts->default_dirs = array( $this->default_scripts_dir );
    2768 
    2769                 wp_enqueue_script( 'one', $this->default_scripts_dir . 'one.js' );
    2770                 wp_enqueue_script( 'two', $this->default_scripts_dir . 'two.js' );
    2771                 wp_enqueue_script( 'three', $this->default_scripts_dir . 'three.js' );
    2772                 wp_enqueue_script( 'four', $this->default_scripts_dir . 'four.js' );
    2773 
    2774                 wp_add_inline_script( 'two', 'console.log("after two");' );
    2775                 wp_add_inline_script( 'three', 'console.log("after three");' );
    2776 
    2777                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=one&amp;ver={$wp_version}'></script>\n";
    2778                 $expected .= "<script src='{$this->default_scripts_dir}two.js?ver={$wp_version}' id='two-js'></script>\n";
    2779                 $expected .= "<script id='two-js-after'>\nconsole.log(\"after two\");\n//# sourceURL=two-js-after\n</script>\n";
    2780                 $expected .= "<script src='{$this->default_scripts_dir}three.js?ver={$wp_version}' id='three-js'></script>\n";
    2781                 $expected .= "<script id='three-js-after'>\nconsole.log(\"after three\");\n//# sourceURL=three-js-after\n</script>\n";
    2782                 $expected .= "<script src='{$this->default_scripts_dir}four.js?ver={$wp_version}' id='four-js'></script>\n";
    2783 
    2784                 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    2785         }
    2786 
    2787         /**
    2788          * @expectedDeprecated WP_Dependencies::add_data()
    2789          *
    2790          * @ticket 14853
    2791          * @ticket 63821
    2792          */
    2793         public function test_wp_add_inline_script_after_and_before_with_concat_and_conditional() {
    2794                 global $wp_scripts;
    2795 
    2796                 $wp_scripts->do_concat    = true;
    2797                 $wp_scripts->default_dirs = array( '/wp-admin/js/', '/wp-includes/js/' ); // Default dirs as in wp-includes/script-loader.php.
    2798 
    2799                 // Conditional scripts should not output.
    2800                 $expected_localized = '';
    2801                 $expected           = '';
    2802 
    2803                 wp_enqueue_script( 'test-example', 'example.com', array(), null );
    2804                 wp_localize_script( 'test-example', 'testExample', array( 'foo' => 'bar' ) );
    2805                 wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
    2806                 wp_add_inline_script( 'test-example', 'console.log("after");' );
    2807                 wp_script_add_data( 'test-example', 'conditional', 'gte IE 9' );
    2808 
    2809                 $this->assertSame( $expected_localized, get_echo( 'wp_print_scripts' ) );
    2810                 $this->assertEqualHTML( $expected, $wp_scripts->print_html );
    2811                 $this->assertTrue( $wp_scripts->do_concat );
    2812         }
    2813 
    2814         /**
    2815          * @ticket 36392
    2816          *
    2817          * @global WP_Scripts $wp_scripts
    2818          * @global string     $wp_version
    2819          */
    2820         public function test_wp_add_inline_script_after_with_concat_and_core_dependency() {
    2821                 global $wp_scripts, $wp_version;
    2822 
    2823                 wp_default_scripts( $wp_scripts );
    2824 
    2825                 $wp_scripts->base_url  = '';
    2826                 $wp_scripts->do_concat = true;
    2827 
    2828                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=jquery-core,jquery-migrate&amp;ver={$wp_version}'></script>\n";
    2829                 $expected .= "<script src='http://example.com' id='test-example-js'></script>\n";
    2830                 $expected .= "<script id='test-example-js-after'>\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n</script>\n";
    2831 
    2832                 wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
    2833                 wp_add_inline_script( 'test-example', 'console.log("after");' );
    2834 
    2835                 wp_print_scripts();
    2836                 $print_scripts = get_echo( '_print_scripts' );
    2837 
    2838                 $this->assertEqualHTML( $expected, $print_scripts );
    2839         }
    2840 
    2841         /**
    2842          * @expectedDeprecated WP_Dependencies::add_data()
    2843          *
    2844          * @ticket 36392
    2845          * @ticket 63821
    2846          */
    2847         public function test_wp_add_inline_script_after_with_concat_and_conditional_and_core_dependency() {
    2848                 global $wp_scripts;
    2849                 wp_default_scripts( $wp_scripts );
    2850 
    2851                 $wp_scripts->base_url  = '';
    2852                 $wp_scripts->do_concat = true;
    2853                 $expected              = '';
    2854 
    2855                 wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
    2856                 wp_add_inline_script( 'test-example', 'console.log("after");' );
    2857                 wp_script_add_data( 'test-example', 'conditional', 'gte IE 9' );
    2858 
    2859                 wp_print_scripts();
    2860                 $print_scripts = get_echo( '_print_scripts' );
    2861 
    2862                 $this->assertEqualHTML( $expected, $print_scripts );
    2863         }
    2864 
    2865         /**
    2866          * @ticket 36392
    2867          *
    2868          * @global WP_Scripts $wp_scripts
    2869          * @global string     $wp_version
    2870          */
    2871         public function test_wp_add_inline_script_before_with_concat_and_core_dependency() {
    2872                 global $wp_scripts, $wp_version;
    2873 
    2874                 wp_default_scripts( $wp_scripts );
    2875                 wp_default_packages( $wp_scripts );
    2876 
    2877                 $wp_scripts->base_url  = '';
    2878                 $wp_scripts->do_concat = true;
    2879 
    2880                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=jquery-core,jquery-migrate&amp;ver={$wp_version}'></script>\n";
    2881                 $expected .= "<script id='test-example-js-before'>\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n</script>\n";
    2882                 $expected .= "<script src='http://example.com' id='test-example-js'></script>\n";
    2883 
    2884                 wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
    2885                 wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
    2886 
    2887                 wp_print_scripts();
    2888                 $print_scripts = get_echo( '_print_scripts' );
    2889 
    2890                 $this->assertEqualHTML( $expected, $print_scripts );
    2891         }
    2892 
    2893         /**
    2894          * @ticket 36392
    2895          *
    2896          * @global WP_Scripts $wp_scripts
    2897          * @global string     $wp_version
    2898          */
    2899         public function test_wp_add_inline_script_before_after_concat_with_core_dependency() {
    2900                 global $wp_scripts, $wp_version;
    2901 
    2902                 wp_default_scripts( $wp_scripts );
    2903                 wp_default_packages( $wp_scripts );
    2904 
    2905                 $wp_scripts->base_url  = '';
    2906                 $wp_scripts->do_concat = true;
    2907 
    2908                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=jquery-core,jquery-migrate,wp-dom-ready,wp-hooks&amp;ver={$wp_version}'></script>\n";
    2909                 $expected .= "<script id='test-example-js-before'>\n";
    2910                 $expected .= "console.log(\"before\");\n//# sourceURL=test-example-js-before\n";
    2911                 $expected .= "</script>\n";
    2912                 $expected .= "<script src='http://example.com' id='test-example-js'></script>\n";
    2913                 $expected .= "<script src='/wp-includes/js/dist/i18n.min.js' id='wp-i18n-js'></script>\n";
    2914                 $expected .= "<script id='wp-i18n-js-after'>\n";
    2915                 $expected .= "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );\n";
    2916                 $expected .= "//# sourceURL=wp-i18n-js-after\n";
    2917                 $expected .= "</script>\n";
    2918                 $expected .= "<script src='/wp-includes/js/dist/a11y.min.js' id='wp-a11y-js'></script>\n";
    2919                 $expected .= "<script src='http://example2.com' id='test-example2-js'></script>\n";
    2920                 $expected .= "<script id='test-example2-js-after'>\nconsole.log(\"after\");\n//# sourceURL=test-example2-js-after\n</script>\n";
    2921                 wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
    2922                 wp_add_inline_script( 'test-example', 'console.log("before");', 'before' );
    2923                 wp_enqueue_script( 'test-example2', 'http://example2.com', array( 'wp-a11y' ), null );
    2924                 wp_add_inline_script( 'test-example2', 'console.log("after");', 'after' );
    2925 
    2926                 // Effectively ignore the output until retrieving it later via `getActualOutput()`.
    2927                 $this->expectOutputRegex( '`.`' );
    2928 
    2929                 wp_print_scripts();
    2930                 _print_scripts();
    2931                 $print_scripts = $this->getActualOutput();
    2932 
    2933                 /*
    2934                  * We've replaced wp-a11y.js with @wordpress/a11y package (see #45066),
    2935                  * and `wp-polyfill` is now a dependency of the packaged wp-a11y.
    2936                  * The packaged scripts contain various version numbers, which are not exposed,
    2937                  * so we will remove all version args from the output.
    2938                  */
    2939                 $print_scripts = preg_replace(
    2940                         '~js\?ver=([^"\']*)~', // Matches `js?ver=X.X.X` and everything to single or double quote.
    2941                         'js',                  // The replacement, `js` without the version arg.
    2942                         $print_scripts         // Printed scripts.
    2943                 );
    2944 
    2945                 $this->assertEqualHTML( $expected, $print_scripts );
    2946         }
    2947 
    2948         /**
    2949          * @ticket 36392
    2950          */
    2951         public function test_wp_add_inline_script_customize_dependency() {
    2952                 global $wp_scripts;
    2953 
    2954                 wp_default_scripts( $wp_scripts );
    2955                 wp_default_packages( $wp_scripts );
    2956 
    2957                 $wp_scripts->base_url  = '';
    2958                 $wp_scripts->do_concat = true;
    2959 
    2960                 $handle = 'customize-dependency';
    2961                 wp_enqueue_script( $handle, '/customize-dependency.js', array( 'customize-controls' ), null );
    2962                 wp_add_inline_script( $handle, 'tryCustomizeDependency()' );
    2963 
    2964                 // Effectively ignore the output until retrieving it later via `getActualOutput()`.
    2965                 $this->expectOutputRegex( '`.`' );
    2966 
    2967                 wp_print_scripts();
    2968                 _print_scripts();
    2969                 $print_scripts = $this->getActualOutput();
    2970 
    2971                 $expected = "<script src='/customize-dependency.js' id='customize-dependency-js'></script>";
    2972                 $this->assertEqualHTMLScriptTagById( $expected, $print_scripts );
    2973 
    2974                 $expected  = "<script id='customize-dependency-js-after'>\n";
    2975                 $expected .= "tryCustomizeDependency()\n";
    2976                 $expected .= "//# sourceURL=customize-dependency-js-after\n";
    2977                 $expected .= '</script>';
    2978                 $this->assertEqualHTMLScriptTagById( $expected, $print_scripts );
    2979         }
    2980 
    2981         /**
    2982          * @ticket 36392
    2983          */
    2984         public function test_wp_add_inline_script_after_for_core_scripts_with_concat_is_limited_and_falls_back_to_no_concat() {
    2985                 global $wp_scripts, $wp_version;
    2986 
    2987                 $wp_scripts->do_concat    = true;
    2988                 $wp_scripts->default_dirs = array( '/wp-admin/js/', '/wp-includes/js/' ); // Default dirs as in wp-includes/script-loader.php.
    2989 
    2990                 wp_enqueue_script( 'one', '/wp-includes/js/script.js' );
    2991                 wp_enqueue_script( 'two', '/wp-includes/js/script2.js', array( 'one' ) );
    2992                 wp_add_inline_script( 'one', 'console.log("after one");', 'after' );
    2993                 wp_enqueue_script( 'three', '/wp-includes/js/script3.js' );
    2994                 wp_enqueue_script( 'four', '/wp-includes/js/script4.js' );
    2995 
    2996                 $expected  = "<script src='/wp-includes/js/script.js?ver={$wp_version}' id='one-js'></script>\n";
    2997                 $expected .= "<script id='one-js-after'>\nconsole.log(\"after one\");\n//# sourceURL=one-js-after\n</script>\n";
    2998                 $expected .= "<script src='/wp-includes/js/script2.js?ver={$wp_version}' id='two-js'></script>\n";
    2999                 $expected .= "<script src='/wp-includes/js/script3.js?ver={$wp_version}' id='three-js'></script>\n";
    3000                 $expected .= "<script src='/wp-includes/js/script4.js?ver={$wp_version}' id='four-js'></script>\n";
    3001 
    3002                 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    3003         }
    3004 
    3005         /**
    3006          * @ticket 36392
    3007          *
    3008          * @global WP_Scripts $wp_scripts
    3009          * @global string     $wp_version
    3010          */
    3011         public function test_wp_add_inline_script_before_third_core_script_prints_two_concat_scripts() {
    3012                 global $wp_scripts, $wp_version;
    3013 
    3014                 $wp_scripts->do_concat    = true;
    3015                 $wp_scripts->default_dirs = array( '/wp-admin/js/', '/wp-includes/js/' ); // Default dirs as in wp-includes/script-loader.php.
    3016 
    3017                 wp_enqueue_script( 'one', '/wp-includes/js/script.js' );
    3018                 wp_enqueue_script( 'two', '/wp-includes/js/script2.js', array( 'one' ) );
    3019                 wp_enqueue_script( 'three', '/wp-includes/js/script3.js' );
    3020                 wp_add_inline_script( 'three', 'console.log("before three");', 'before' );
    3021                 wp_enqueue_script( 'four', '/wp-includes/js/script4.js' );
    3022 
    3023                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=one,two&amp;ver={$wp_version}'></script>\n";
    3024                 $expected .= "<script id='three-js-before'>\nconsole.log(\"before three\");\n//# sourceURL=three-js-before\n</script>\n";
    3025                 $expected .= "<script src='/wp-includes/js/script3.js?ver={$wp_version}' id='three-js'></script>\n";
    3026                 $expected .= "<script src='/wp-includes/js/script4.js?ver={$wp_version}' id='four-js'></script>\n";
    30272641
    30282642                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    … …  
    38193433
    38203434        /**
    3821          * @ticket 55628
    3822          *
    3823          * @covers ::wp_set_script_translations
    3824          *
    3825          * @global WP_Scripts $wp_scripts
    3826          * @global string     $wp_version
    3827          */
    3828         public function test_wp_external_wp_i18n_print_order() {
    3829                 global $wp_scripts, $wp_version;
    3830 
    3831                 $wp_scripts->do_concat    = true;
    3832                 $wp_scripts->default_dirs = array( '/default/' );
    3833 
    3834                 // wp-i18n script in a non-default directory.
    3835                 wp_register_script( 'wp-i18n', '/plugins/wp-i18n.js', array(), null );
    3836                 // Script in default dir that's going to be concatenated.
    3837                 wp_enqueue_script( 'jquery-core', '/default/jquery-core.js', array(), null );
    3838                 // Script in default dir that depends on wp-i18n.
    3839                 wp_enqueue_script( 'common', '/default/common.js', array(), null );
    3840                 wp_set_script_translations( 'common' );
    3841 
    3842                 $print_scripts = get_echo(
    3843                         static function () {
    3844                                 wp_print_scripts();
    3845                                 _print_scripts();
    3846                         }
    3847                 );
    3848 
    3849                 // The non-default script should end concatenation and maintain order.
    3850                 $expected  = "<script src='/wp-admin/load-scripts.php?load%5Bchunk_0%5D=jquery-core&amp;ver={$wp_version}'></script>\n";
    3851                 $expected .= "<script src='/plugins/wp-i18n.js' id='wp-i18n-js'></script>\n";
    3852                 $expected .= "<script src='/default/common.js' id='common-js'></script>\n";
    3853 
    3854                 $this->assertEqualHTML( $expected, $print_scripts );
    3855         }
    3856 
    3857         /**
    38583435         * Ensure tinymce scripts aren't loading async.
    38593436         *
    … …  
    38753452         *
    38763453         * @covers ::wp_register_tinymce_scripts
    3877          *
    3878          * @dataProvider data_register_tinymce_scripts_unbundled
    3879          *
    3880          * @param bool $concatenate Value of the `$concatenate_scripts` global.
    3881          */
    3882         public function test_register_tinymce_scripts_unbundled( bool $concatenate ): void {
    3883                 global $concatenate_scripts;
    3884 
    3885                 $concatenate_scripts = $concatenate;
    3886 
     3454         */
     3455        public function test_register_tinymce_scripts_unbundled(): void {
    38873456                $wp_scripts = wp_scripts();
    38883457                wp_register_tinymce_scripts( $wp_scripts );
    … …  
    38983467                $this->assertMatchesRegularExpression( '#/js/tinymce/plugins/compat3x/plugin(\.min)?\.js$#', $tinymce->src );
    38993468                $this->assertSame( array( 'wp-tinymce-root' ), $tinymce->deps );
    3900         }
    3901 
    3902         /**
    3903          * Data provider for test_register_tinymce_scripts_unbundled().
    3904          *
    3905          * @return array<non-falsy-string, array{ concatenate: bool }>
    3906          */
    3907         public function data_register_tinymce_scripts_unbundled(): array {
    3908                 return array(
    3909                         'concatenated'     => array(
    3910                                 'concatenate' => true,
    3911                         ),
    3912                         'not concatenated' => array(
    3913                                 'concatenate' => false,
    3914                         ),
    3915                 );
    39163469        }
    39173470
    … …  
    44013954
    44023955                $expected = <<<HTML
    4403 <script id="# test/</script> #-js-extra">
    4404 var test = [];
    4405 //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-extra
    4406 </script>
    4407 <script id="# test/</script> #-js-before">
    4408 "before";
    4409 //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-before
    4410 </script>
    4411 <script src="/example.js?ver=0.0" id="# test/</script> #-js"></script>
    4412 <script id="# test/</script> #-js-after">
    4413 "after";
    4414 //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-after
    4415 </script>
    4416 
    4417 HTML;
     3956                <script id="# test/</script> #-js-extra">
     3957                var test = [];
     3958                //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-extra
     3959                </script>
     3960                <script id="# test/</script> #-js-before">
     3961                "before";
     3962                //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-before
     3963                </script>
     3964                <script src="/example.js?ver=0.0" id="# test/</script> #-js"></script>
     3965                <script id="# test/</script> #-js-after">
     3966                "after";
     3967                //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-after
     3968                </script>
     3969
     3970                HTML;
    44183971
    44193972                $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    4420         }
    4421 
    4422         /**
    4423          * @ticket 63887
    4424          *
    4425          * @global WP_Scripts $wp_scripts
    4426          * @global bool $concatenate_scripts
    4427          * @global string $wp_version
    4428          */
    4429         public function test_source_url_with_concat() {
    4430                 global $wp_scripts, $concatenate_scripts, $wp_version;
    4431 
    4432                 $concatenate_scripts = true;
    4433 
    4434                 $wp_scripts->do_concat    = true;
    4435                 $wp_scripts->default_dirs = array( $this->default_scripts_dir );
    4436 
    4437                 wp_enqueue_script( 'one', $this->default_scripts_dir . '1.js' );
    4438                 wp_enqueue_script( 'two', $this->default_scripts_dir . '2.js' );
    4439                 wp_localize_script( 'one', 'one', array( 'key' => 'val' ) );
    4440                 wp_localize_script( 'two', 'two', array( 'key' => 'val' ) );
    4441 
    4442                 wp_print_scripts();
    4443                 $print_scripts = get_echo( '_print_scripts' );
    4444 
    4445                 $expected = <<<HTML
    4446                 <script>
    4447                 var one = {"key":"val"};var two = {"key":"val"};
    4448                 //# sourceURL=js-inline-concat-one%2Ctwo
    4449                 </script>
    4450                 <script src="/wp-admin/load-scripts.php?load%5Bchunk_0%5D=one,two&#038;ver={$wp_version}"></script>
    4451 
    4452                 HTML;
    4453 
    4454                 $this->assertEqualHTML( $expected, $print_scripts );
    44553973        }
    44563974
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r64485 r64585  
    1010 */
    1111class Tests_Dependencies_Styles extends WP_UnitTestCase {
    12         private $old_wp_styles;
    13         private $old_wp_scripts;
     12        private ?WP_Styles $old_wp_styles = null;
     13
     14        private ?WP_Scripts $old_wp_scripts = null;
    1415
    1516        public function set_up() {
    1617                parent::set_up();
    1718
    18                 if ( empty( $GLOBALS['wp_styles'] ) ) {
    19                         $GLOBALS['wp_styles'] = null;
    20                 }
    21 
    22                 $this->old_wp_styles = $GLOBALS['wp_styles'];
    23 
    24                 if ( empty( $GLOBALS['wp_scripts'] ) ) {
    25                         $GLOBALS['wp_scripts'] = null;
    26                 }
    27 
    28                 $this->old_wp_styles = $GLOBALS['wp_scripts'];
     19                $old_wp_styles        = $GLOBALS['wp_styles'] ?? null;
     20                $old_wp_scripts       = $GLOBALS['wp_scripts'] ?? null;
     21                $this->old_wp_styles  = $old_wp_styles instanceof WP_Styles ? $old_wp_styles : null;
     22                $this->old_wp_scripts = $old_wp_scripts instanceof WP_Scripts ? $old_wp_scripts : null;
    2923
    3024                remove_action( 'wp_default_styles', 'wp_default_styles' );
    … …  
    199193
    200194        /**
    201          * Test if inline styles work with concatenation
     195         * Tests that inline styles are printed right away when the deprecated `do_concat` property is set.
    202196         *
    203197         * @global WP_Styles $wp_styles
    204198         * @ticket 24813
     199         * @ticket 57548
    205200         */
    206201        public function test_inline_styles_concat() {
    207202                global $wp_styles;
    208203
    209                 $wp_styles->do_concat    = true;
    210                 $wp_styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' ); // Default dirs as in wp-includes/script-loader.php.
     204                // The deprecated property is set as plugins may still do, to verify that it no longer has any effect.
     205                $wp_styles->do_concat = true;
    211206
    212207                $style  = ".thing {\n";
    … …  
    217212                $expected .= "<style id='handle-inline-css'>\n";
    218213                $expected .= "$style\n";
     214                $expected .= "/*# sourceURL=handle-inline-css */\n";
    219215                $expected .= "</style>\n";
    220216
    … …  
    222218                wp_add_inline_style( 'handle', $style );
    223219
    224                 wp_print_styles();
    225                 $this->assertEqualHTML( $expected, $wp_styles->print_html );
     220                $this->assertEqualHTML( $expected, get_echo( 'wp_print_styles' ) );
     221                $this->assertSame( '', $wp_styles->print_html );
     222        }
     223
     224        /**
     225         * Tests that the deprecated filters for printing styles no longer keep them from being printed.
     226         *
     227         * @ticket 57548
     228         *
     229         * @covers ::print_admin_styles
     230         * @covers ::print_late_styles
     231         *
     232         * @expectedDeprecated print_admin_styles
     233         * @expectedDeprecated print_late_styles
     234         */
     235        public function test_print_styles_filters_are_deprecated(): void {
     236                add_filter( 'print_admin_styles', '__return_false' );
     237                add_filter( 'print_late_styles', '__return_false' );
     238
     239                wp_enqueue_style( 'admin', '/admin.css', array(), null );
     240
     241                $this->assertEqualHTML( "<link rel='stylesheet' id='admin-css' href='/admin.css' media='all' />\n", get_echo( 'print_admin_styles' ), '<body>', 'Expected the admin styles to be printed.' );
     242
     243                wp_enqueue_style( 'late', '/late.css', array(), null );
     244
     245                $this->assertEqualHTML( "<link rel='stylesheet' id='late-css' href='/late.css' media='all' />\n", get_echo( 'print_late_styles' ), '<body>', 'Expected the late styles to be printed.' );
     246        }
     247
     248        /**
     249         * Tests that WP_Styles::in_default_dir() is deprecated but still works.
     250         *
     251         * @ticket 57548
     252         *
     253         * @covers WP_Styles::in_default_dir
     254         *
     255         * @expectedDeprecated WP_Styles::in_default_dir
     256         */
     257        public function test_in_default_dir_is_deprecated(): void {
     258                $wp_styles               = wp_styles();
     259                $wp_styles->default_dirs = array( '/wp-includes/css/' );
     260
     261                $this->assertTrue( $wp_styles->in_default_dir( '/wp-includes/css/file' ) );
    226262        }
    227263
    … …  
    899935
    900936                $expected = <<<HTML
    901 <link rel='stylesheet' href="/example.css?ver=0.0" id="# test/</style> #-css" media="all">
    902 <style id="# test/</style> #-inline-css">
    903 custom-el { content: "ok"; }
    904 /*# sourceURL=%23%20test%2F%3C%2Fstyle%3E%20%23-inline-css */
    905 </style>
    906 
    907 HTML;
     937                <link rel='stylesheet' href="/example.css?ver=0.0" id="# test/</style> #-css" media="all">
     938                <style id="# test/</style> #-inline-css">
     939                custom-el { content: "ok"; }
     940                /*# sourceURL=%23%20test%2F%3C%2Fstyle%3E%20%23-inline-css */
     941                </style>
     942
     943                HTML;
    908944
    909945                $this->assertEqualHTML( $expected, get_echo( 'wp_print_styles' ) );
    910         }
    911 
    912         /**
    913          * @ticket 63887
    914          *
    915          * @global WP_Styles $wp_styles
    916          * @global string    $wp_version
    917          */
    918         public function test_source_url_with_concat() {
    919                 global $wp_styles, $wp_version;
    920                 add_theme_support( 'html5', array( 'style' ) );
    921 
    922                 $wp_styles->do_concat    = true;
    923                 $wp_styles->default_dirs = array( '/wp-admin/' );
    924 
    925                 wp_enqueue_style( 'one', '/wp-admin/1.css' );
    926                 wp_enqueue_style( 'two', '/wp-admin/2.css' );
    927                 wp_add_inline_style( 'one', 'h1 { background: blue; }' );
    928                 wp_add_inline_style( 'two', 'h2 { color: green; }' );
    929 
    930                 wp_print_styles();
    931                 $printed = get_echo( '_print_styles' );
    932 
    933                 $expected = <<<HTML
    934 <link
    935         rel="stylesheet"
    936         href="/wp-admin/load-styles.php?dir=ltr&load%5Bchunk_0%5D=one,two&ver={$wp_version}"
    937         media="all"
    938 >
    939 <style>
    940 h1 { background: blue; }h2 { color: green; }
    941 /*# sourceURL=css-inline-concat-one%2Ctwo */
    942 </style>
    943 
    944 HTML;
    945 
    946                 $this->assertEqualHTML( $expected, $printed );
    947946        }
    948947
  • trunk/tests/phpunit/tests/dependencies/wpPrefetchAdminAssets.php

    r64121 r64585  
    22/**
    33 * Tests for {@see wp_prefetch_admin_assets()}.
    4  *
    5  * Prefetching only happens when concatenation is off. Each test turns it off with the
    6  * {@see 'wp_should_concatenate_admin_scripts'} filter, so that it does not depend on the
    7  * `CONCATENATE_SCRIPTS` and `SCRIPT_DEBUG` constants, which cannot be changed once defined.
    84 *
    95 * @package WordPress
    … …  
    3228
    3329        /**
    34          * Gives each test fresh script and style registries, since several tests modify them, and turns
    35          * concatenation off.
     30         * Gives each test fresh script and style registries, since several tests modify them.
    3631         */
    3732        public function set_up(): void {
    … …  
    4439
    4540                $this->original_script_name = $_SERVER['SCRIPT_NAME'] ?? null;
    46 
    47                 add_filter( 'wp_should_concatenate_admin_scripts', '__return_false' );
    4841        }
    4942
    … …  
    7063
    7164        /**
    72          * Tests that nothing is prefetched from the login screen when the admin concatenates its assets.
    73          *
    74          * @ticket 57548
    75          */
    76         public function test_login_prints_nothing_when_admin_concatenates(): void {
    77                 add_filter( 'wp_should_concatenate_admin_scripts', '__return_true' );
    78 
    79                 $this->assertSame( array(), $this->get_prefetched_on_login() );
    80         }
    81 
    82         /**
    83          * Tests that the login screen predicts what the admin will do rather than reading the
    84          * `$concatenate_scripts` global, which script_concat_settings() may have settled on false before
    85          * 'login_init' fired.
     65         * Tests that the `$concatenate_scripts` global no longer stops prefetching from the login screen,
     66         * as nothing is concatenated.
    8667         *
    8768         * @ticket 57548
    … …  
    9071                $GLOBALS['concatenate_scripts'] = true;
    9172
    92                 $this->assertNotSame( array(), $this->get_prefetched_on_login(), 'Expected prefetching when the admin will not concatenate.' );
    93 
    94                 $GLOBALS['concatenate_scripts'] = false;
    95                 add_filter( 'wp_should_concatenate_admin_scripts', '__return_true' );
    96 
    97                 $this->assertSame( array(), $this->get_prefetched_on_login(), 'Expected no prefetching when the admin will concatenate.' );
    98         }
    99 
    100         /**
    101          * Tests that an admin screen goes by the `$concatenate_scripts` global, which has settled by the
    102          * time its head is printed, so a plugin setting the global is respected.
    103          *
    104          * @ticket 57548
    105          */
    106         public function test_admin_screen_uses_concatenate_scripts_global(): void {
     73                $this->assertNotSame( array(), $this->get_prefetched_on_login() );
     74        }
     75
     76        /**
     77         * Tests that the `$concatenate_scripts` global no longer stops prefetching from an admin screen,
     78         * as nothing is concatenated.
     79         *
     80         * @ticket 57548
     81         */
     82        public function test_admin_screen_ignores_concatenate_scripts_global(): void {
    10783                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
    10884
    10985                $GLOBALS['concatenate_scripts'] = true;
    11086
    111                 $this->assertSame( array(), $this->get_prefetched_on_admin_screen( 'dashboard' ), 'Expected no prefetching when the global says to concatenate.' );
    112 
    113                 $GLOBALS['concatenate_scripts'] = false;
    114                 add_filter( 'wp_should_concatenate_admin_scripts', '__return_true' );
    115 
    116                 $this->assertNotSame( array(), $this->get_prefetched_on_admin_screen( 'dashboard' ), 'Expected prefetching when the global says not to concatenate.' );
    117         }
    118 
    119         /**
    120          * Tests that an admin screen settles the `$concatenate_scripts` global with script_concat_settings()
    121          * when nothing has done so yet.
    122          *
    123          * @ticket 57548
    124          */
    125         public function test_admin_screen_settles_concatenate_scripts_global(): void {
    126                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
    127                 add_filter( 'wp_should_concatenate_admin_scripts', '__return_true' );
    128 
    129                 $this->assertSame( array(), $this->get_prefetched_on_admin_screen( 'dashboard' ) );
    130                 $this->assertTrue( $GLOBALS['concatenate_scripts'] );
     87                $this->assertSame( 0, did_action( 'login_init' ), 'Expected the request not to be one for the login screen.' );
     88                $this->assertNotSame( array(), $this->get_prefetched_on_admin_screen( 'dashboard' ) );
    13189        }
    13290
Note: See TracChangeset for help on using the changeset viewer.