Changeset 64585
- Timestamp:
- 10/19/2026 10:45:25 PM (3 weeks ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 19 edited
-
src/wp-admin/includes/class-wp-debug-data.php (modified) (2 diffs)
-
src/wp-admin/includes/noop.php (modified) (1 diff)
-
src/wp-admin/load-scripts.php (modified) (1 diff)
-
src/wp-admin/load-styles.php (modified) (1 diff)
-
src/wp-includes/class-wp-dependencies.php (modified) (2 diffs)
-
src/wp-includes/class-wp-editor.php (modified) (3 diffs)
-
src/wp-includes/class-wp-scripts.php (modified) (17 diffs)
-
src/wp-includes/class-wp-styles.php (modified) (12 diffs)
-
src/wp-includes/default-constants.php (modified) (1 diff)
-
src/wp-includes/deprecated.php (modified) (1 diff)
-
src/wp-includes/global-styles-and-settings.php (modified) (1 diff)
-
src/wp-includes/script-loader.php (modified) (21 diffs)
-
tests/phpstan/base.neon (modified) (2 diffs)
-
tests/phpstan/baselines/variable.undefined.neon (modified) (1 diff)
-
tests/phpunit/tests/dependencies.php (modified) (2 diffs)
-
tests/phpunit/tests/dependencies/scriptConcatSettings.php (modified) (3 diffs)
-
tests/phpunit/tests/dependencies/scripts.php (modified) (29 diffs)
-
tests/phpunit/tests/dependencies/styles.php (modified) (5 diffs)
-
tests/phpunit/tests/dependencies/wpPrefetchAdminAssets.php (modified) (5 diffs)
-
tests/phpunit/tests/dependencies/wpShouldConcatenateAdminScripts.php (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-debug-data.php
r64321 r64585 1510 1510 } 1511 1511 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 1521 1512 // Check WP_ENVIRONMENT_TYPE. 1522 1513 if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) { … … 1593 1584 'value' => WP_CACHE ? __( 'Enabled' ) : __( 'Disabled' ), 1594 1585 'debug' => WP_CACHE, 1595 ),1596 'CONCATENATE_SCRIPTS' => array(1597 'label' => 'CONCATENATE_SCRIPTS',1598 'value' => $concatenate_scripts,1599 'debug' => $concatenate_scripts_debug,1600 1586 ), 1601 1587 'WP_ENVIRONMENT_TYPE' => array( -
trunk/src/wp-admin/includes/noop.php
r56641 r64585 1 1 <?php 2 2 /** 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. 4 7 * 5 8 * @package WordPress 6 9 * @subpackage Administration 7 10 * @since 4.4.0 11 * @deprecated 7.2.0 Scripts and styles are no longer concatenated. 8 12 */ 9 13 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; 14 if ( function_exists( '_deprecated_file' ) ) { 15 _deprecated_file( basename( __FILE__ ), '7.2.0' ); 30 16 } 31 32 /**33 * @ignore34 */35 function esc_attr() {}36 37 /**38 * @ignore39 */40 function apply_filters() {}41 42 /**43 * @ignore44 */45 function get_option() {}46 47 /**48 * @ignore49 */50 function is_lighttpd_before_150() {}51 52 /**53 * @ignore54 */55 function add_action() {}56 57 /**58 * @ignore59 */60 function did_action() {}61 62 /**63 * @ignore64 */65 function do_action_ref_array() {}66 67 /**68 * @ignore69 */70 function get_bloginfo() {}71 72 /**73 * @ignore74 */75 function is_admin() {76 return true;77 }78 79 /**80 * @ignore81 */82 function site_url() {}83 84 /**85 * @ignore86 */87 function admin_url() {}88 89 /**90 * @ignore91 */92 function home_url() {}93 94 /**95 * @ignore96 */97 function includes_url() {}98 99 /**100 * @ignore101 */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 1 1 <?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 */ 2 13 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; 14 http_response_code( 410 ); 15 header( 'Content-Type: text/plain; charset=UTF-8' ); 16 echo 'Scripts are no longer concatenated.'; 77 17 exit; -
trunk/src/wp-admin/load-styles.php
r59341 r64585 1 1 <?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 */ 2 13 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; 14 http_response_code( 410 ); 15 header( 'Content-Type: text/plain; charset=UTF-8' ); 16 echo 'Styles are no longer concatenated.'; 102 17 exit; -
trunk/src/wp-includes/class-wp-dependencies.php
r64235 r64585 535 535 * 536 536 * @since 6.7.0 537 * @deprecated 7.2.0 Scripts and styles are no longer concatenated by load-scripts.php or load-styles.php. 537 538 * 538 539 * @global string $wp_version The WordPress version string. … … 544 545 */ 545 546 public function get_etag( $load ) { 546 /*547 * Note: wp_get_wp_version() is not used here, as this file can be included548 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case549 * wp-includes/functions.php is not loaded.550 */551 547 global $wp_version; 548 549 _deprecated_function( __METHOD__, '7.2.0' ); 552 550 553 551 $etag = "WP:{$wp_version};"; -
trunk/src/wp-includes/class-wp-editor.php
r64320 r64585 1520 1520 * Force uncompressed TinyMCE when a custom theme has been defined. 1521 1521 * 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. 1525 1526 * 1526 1527 * @since 5.0.0 … … 1549 1550 * 1550 1551 * @since 4.8.0 1551 *1552 * @global bool $concatenate_scripts1553 1552 */ 1554 1553 public static function print_tinymce_scripts() { 1555 global $concatenate_scripts;1556 1557 1554 if ( self::$tinymce_scripts_printed ) { 1558 1555 return; … … 1560 1557 1561 1558 self::$tinymce_scripts_printed = true; 1562 1563 if ( ! isset( $concatenate_scripts ) ) {1564 script_concat_settings();1565 }1566 1559 1567 1560 wp_print_scripts( array( 'wp-tinymce' ) ); -
trunk/src/wp-includes/class-wp-scripts.php
r64120 r64585 58 58 * 59 59 * @since 2.8.0 60 * @deprecated 7.2.0 Scripts are no longer concatenated. 60 61 * @var string 61 62 */ … … 75 76 * 76 77 * @since 2.8.0 78 * @deprecated 7.2.0 Scripts are no longer concatenated. 77 79 * @var bool 78 80 */ … … 84 86 * 85 87 * @since 2.8.0 88 * @deprecated 7.2.0 Scripts are no longer concatenated. 86 89 * @var string 87 90 */ … … 92 95 * 93 96 * @since 2.8.0 97 * @deprecated 7.2.0 Scripts are no longer concatenated. 94 98 * @var string 95 99 */ … … 103 107 * 104 108 * @since 2.8.0 109 * @deprecated 7.2.0 Scripts are no longer concatenated. 105 110 * @var string 106 111 */ … … 114 119 * 115 120 * @since 2.8.0 121 * @deprecated 7.2.0 Scripts are no longer concatenated. 116 122 * @var string 117 123 */ … … 121 127 * List of default directories. 122 128 * 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() 124 135 * @see wp_default_scripts() 125 136 * @var string[]|null … … 225 236 public function print_extra_script( $handle, $display = true ) { 226 237 $output = $this->get_data( $handle, 'data' ); 227 if ( ! $output ) {238 if ( ! is_string( $output ) || ! $output ) { 228 239 return null; 229 240 } 230 241 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 ); 244 246 245 247 if ( ! $display ) { … … 301 303 if ( $obj->extra['conditional'] ?? false ) { 302 304 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 . '&' . $this->args[ $handle ] : $this->args[ $handle ];313 305 } 314 306 … … 349 341 } 350 342 351 /*352 * Prevent concatenation of scripts if the text domain is defined353 * to ensure the dependency order is respected.354 */355 $translations_stop_concat = ! empty( $obj->textdomain );356 357 343 $translations = $this->print_translations( $handle, false ); 358 344 if ( $translations ) { … … 369 355 } 370 356 371 if ( $this->do_concat ) {372 /**373 * Filters the script loader source.374 *375 * @since 2.2.0376 *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 403 357 $this->print_extra_script( $handle ); 404 358 … … 406 360 if ( ! $src ) { 407 361 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; 413 363 } 414 364 … … 466 416 $tag = apply_filters( 'script_loader_tag', $tag, $handle, $src ); 467 417 468 if ( $this->do_concat ) { 469 $this->print_html .= $tag; 470 } else { 471 echo $tag; 472 } 418 echo $tag; 473 419 474 420 return true; … … 532 478 } 533 479 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 */ 535 488 $src = apply_filters( 'script_loader_src', $src, $handle ); 536 489 … … 611 564 } 612 565 613 /*614 * Print sourceURL comment regardless of concatenation.615 *616 * Inline scripts prevent scripts from being concatenated, so617 * sourceURL comments are safe to print for inline scripts.618 */619 566 $data[] = sprintf( 620 567 '//# sourceURL=%s', … … 872 819 * 873 820 * @since 2.8.0 821 * @deprecated 7.2.0 Scripts are no longer concatenated. 874 822 * 875 823 * @param string $src The source of the enqueued script. … … 877 825 */ 878 826 public function in_default_dir( $src ) { 827 _deprecated_function( __METHOD__, '7.2.0' ); 828 879 829 if ( ! $this->default_dirs ) { 880 830 return true; -
trunk/src/wp-includes/class-wp-styles.php
r64120 r64585 59 59 * 60 60 * @since 2.8.0 61 * @deprecated 7.2.0 Styles are no longer concatenated. 61 62 * @var string 62 63 */ … … 76 77 * 77 78 * @since 2.8.0 79 * @deprecated 7.2.0 Styles are no longer concatenated. 78 80 * @var bool 79 81 */ … … 85 87 * 86 88 * @since 2.8.0 89 * @deprecated 7.2.0 Styles are no longer concatenated. 87 90 * @var string 88 91 */ … … 93 96 * 94 97 * @since 3.3.0 98 * @deprecated 7.2.0 Styles are no longer concatenated. 95 99 * @var string 96 100 */ … … 100 104 * List of default directories. 101 105 * 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() 103 112 * @see wp_default_styles() 104 113 * @var string[]|null … … 145 154 return false; 146 155 } 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 . '&' . $this->args[ $handle ] : $this->args[ $handle ];155 }156 156 157 157 $src = $obj->src; … … 168 168 } 169 169 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 181 170 $media = $obj->args ?? 'all'; 182 171 … … 184 173 if ( ! $src ) { 185 174 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; 191 176 } 192 177 … … 248 233 } 249 234 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; 259 237 260 238 return true; … … 351 329 } 352 330 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 ); 372 347 373 348 $output = implode( "\n", $output ); … … 553 528 * 554 529 * @since 2.8.0 530 * @deprecated 7.2.0 Styles are no longer concatenated. 555 531 * 556 532 * @param string $src The source of the enqueued style. … … 558 534 */ 559 535 public function in_default_dir( $src ) { 536 _deprecated_function( __METHOD__, '7.2.0' ); 537 560 538 if ( ! $this->default_dirs ) { 561 539 return true; -
trunk/src/wp-includes/default-constants.php
r64115 r64585 116 116 117 117 /* 118 * Add define( 'SCRIPT_DEBUG', true ); to wp-config.php to enable loading of non-minified ,119 * non-concatenatedscripts and stylesheets.118 * Add define( 'SCRIPT_DEBUG', true ); to wp-config.php to enable loading of non-minified 119 * scripts and stylesheets. 120 120 */ 121 121 if ( ! defined( 'SCRIPT_DEBUG' ) ) { -
trunk/src/wp-includes/deprecated.php
r64489 r64585 6603 6603 6604 6604 /** 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 */ 6620 function 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 */ 6648 function _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 */ 6665 function _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 /** 6605 6676 * Starts an output buffer that sends the Document-Isolation-Policy header 6606 6677 * and adds crossorigin="anonymous" to cross-origin resources. -
trunk/src/wp-includes/global-styles-and-settings.php
r64436 r64585 388 388 } 389 389 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' ); 402 391 403 392 $theme_has_support[ $stylesheet ] = file_exists( $path ); -
trunk/src/wp-includes/script-loader.php
r64496 r64585 3 3 * WordPress scripts and styles default loader. 4 4 * 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. 10 7 * 11 8 * @package WordPress … … 59 56 $suffix = wp_scripts_get_suffix(); 60 57 $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 has64 * settled them until now, which the 'wp_should_concatenate_admin_scripts' filter documents.65 */66 script_concat_settings();67 58 68 59 // Load tinymce.js when running from /src, otherwise tinymce.min.js. … … 693 684 694 685 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' ); 710 687 711 688 if ( ! defined( 'SCRIPT_DEBUG' ) ) { … … 752 729 $scripts->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : ''; 753 730 $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. 755 732 756 733 $scripts->add( 'utils', "/wp-includes/js/utils$suffix.js" ); … … 1560 1537 global $editor_styles; 1561 1538 1562 /*1563 * Include an unmodified $wp_version.1564 *1565 * Note: wp_get_wp_version() is not used here, as this file can be included1566 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case1567 * 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 included1574 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case1575 * the polyfills from wp-includes/compat.php are not loaded.1576 */1577 define( 'SCRIPT_DEBUG', false !== strpos( $wp_version, '-src' ) );1578 }1579 1580 1539 $guessurl = site_url(); 1581 1540 … … 1587 1546 $styles->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : ''; 1588 1547 $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. 1591 1550 1592 1551 // Open Sans is no longer used by core, but may be relied upon by themes and plugins. … … 1621 1580 $styles->add( 'colors', true, array( 'wp-admin', 'buttons' ) ); 1622 1581 1623 $suffix = SCRIPT_DEBUG ? '' : '.min';1582 $suffix = wp_scripts_get_suffix(); 1624 1583 1625 1584 // Admin CSS. … … 2158 2117 * @see wp_print_scripts() 2159 2118 * 2160 * @global bool $concatenate_scripts2161 *2162 2119 * @return string[] Handles of the scripts that were printed. 2163 2120 */ 2164 2121 function print_head_scripts() { 2165 global $concatenate_scripts;2166 2167 2122 if ( ! did_action( 'wp_print_scripts' ) ) { 2168 2123 /** This action is documented in wp-includes/functions.wp-scripts.php */ … … 2171 2126 2172 2127 $wp_scripts = wp_scripts(); 2173 2174 script_concat_settings();2175 $wp_scripts->do_concat = $concatenate_scripts;2176 2128 $wp_scripts->do_head_items(); 2177 2129 … … 2180 2132 * 2181 2133 * @since 2.8.0 2134 * @deprecated 7.2.0 Scripts are no longer concatenated, so there is nothing for this filter to control. 2182 2135 * 2183 2136 * @param bool $print Whether to print the head scripts. Default true. 2184 2137 */ 2185 if ( apply_filters( 'print_head_scripts', true ) ) { 2186 _print_scripts(); 2187 } 2138 apply_filters_deprecated( 'print_head_scripts', array( true ), '7.2.0' ); 2188 2139 2189 2140 $wp_scripts->reset(); … … 2197 2148 * 2198 2149 * @global WP_Scripts $wp_scripts 2199 * @global bool $concatenate_scripts2200 2150 * 2201 2151 * @return string[] Handles of the scripts that were printed. 2202 2152 */ 2203 2153 function print_footer_scripts() { 2204 global $wp_scripts , $concatenate_scripts;2154 global $wp_scripts; 2205 2155 2206 2156 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 2207 2157 return array(); // No need to run if not instantiated. 2208 2158 } 2209 script_concat_settings();2210 $wp_scripts->do_concat = $concatenate_scripts;2211 2159 $wp_scripts->do_footer_items(); 2212 2160 … … 2215 2163 * 2216 2164 * @since 2.8.0 2165 * @deprecated 7.2.0 Scripts are no longer concatenated, so there is nothing for this filter to control. 2217 2166 * 2218 2167 * @param bool $print Whether to print the footer scripts. Default true. 2219 2168 */ 2220 if ( apply_filters( 'print_footer_scripts', true ) ) { 2221 _print_scripts(); 2222 } 2169 apply_filters_deprecated( 'print_footer_scripts', array( true ), '7.2.0' ); 2223 2170 2224 2171 $wp_scripts->reset(); 2225 2172 return $wp_scripts->done; 2226 }2227 2228 /**2229 * Prints scripts (internal use only)2230 *2231 * @since 2.8.02232 *2233 * @ignore2234 *2235 * @global WP_Scripts $wp_scripts2236 */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 }2261 2173 } 2262 2174 … … 2343 2255 * @since 2.8.0 2344 2256 * 2345 * @global bool $concatenate_scripts2346 *2347 2257 * @return string[] Handles of the styles that were printed. 2348 2258 */ 2349 2259 function print_admin_styles() { 2350 global $concatenate_scripts;2351 2352 2260 $wp_styles = wp_styles(); 2353 2354 script_concat_settings();2355 $wp_styles->do_concat = $concatenate_scripts;2356 2261 $wp_styles->do_items( false ); 2357 2262 … … 2360 2265 * 2361 2266 * @since 2.8.0 2267 * @deprecated 7.2.0 Styles are no longer concatenated, so there is nothing for this filter to control. 2362 2268 * 2363 2269 * @param bool $print Whether to print the admin styles. Default true. 2364 2270 */ 2365 if ( apply_filters( 'print_admin_styles', true ) ) { 2366 _print_styles(); 2367 } 2271 apply_filters_deprecated( 'print_admin_styles', array( true ), '7.2.0' ); 2368 2272 2369 2273 $wp_styles->reset(); … … 2377 2281 * 2378 2282 * @global WP_Styles $wp_styles 2379 * @global bool $concatenate_scripts2380 2283 * 2381 2284 * @return string[]|null 2382 2285 */ 2383 2286 function print_late_styles() { 2384 global $wp_styles , $concatenate_scripts;2287 global $wp_styles; 2385 2288 2386 2289 if ( ! ( $wp_styles instanceof WP_Styles ) ) { … … 2388 2291 } 2389 2292 2390 script_concat_settings();2391 $wp_styles->do_concat = $concatenate_scripts;2392 2293 $wp_styles->do_footer_items(); 2393 2294 … … 2396 2297 * 2397 2298 * @since 3.3.0 2299 * @deprecated 7.2.0 Styles are no longer concatenated, so there is nothing for this filter to control. 2398 2300 * 2399 2301 * @param bool $print Whether to print the 'late' styles. Default true. 2400 2302 */ 2401 if ( apply_filters( 'print_late_styles', true ) ) { 2402 _print_styles(); 2403 } 2303 apply_filters_deprecated( 'print_late_styles', array( true ), '7.2.0' ); 2404 2304 2405 2305 $wp_styles->reset(); … … 2408 2308 2409 2309 /** 2410 * Prints styles (internal use only).2411 *2412 * @ignore2413 * @since 3.3.02414 */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.02454 * @since 7.2.0 The `$compress_scripts` and `$compress_css` globals default to false, as PHP compression2455 * of scripts and styles was removed in 4.9.9.2456 *2457 * @global bool $concatenate_scripts2458 * @global bool $compress_scripts2459 * @global bool $compress_css2460 */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 when2484 * the global has not already been set. It is also how wp_prefetch_admin_assets() predicts, from the2485 * 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 while2488 * concatenation is still an option, and once concatenation is retired, there is nothing left for2489 * them to decide. Do not rely on them; setting the `$concatenate_scripts` global remains the way2490 * to override concatenation on a request.2491 *2492 * @since 7.2.02493 *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 on2504 * the request where it is set.2505 *2506 * An admin screen settles the global the first time scripts are registered, when the2507 * {@see 'wp_default_scripts'} action registers TinyMCE. That can be as early as while plugins2508 * load, before the theme's functions.php, whereas the login screen reads this filter only when2509 * it prints, to predict what the admin will do. So add a callback when a plugin loads, rather2510 * 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.02513 *2514 * @param bool $concatenate Whether scripts and styles are concatenated. Default false, unless the2515 * `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 /**2521 2310 * Prints prefetch links for the assets of the screen the user is most likely to open next. 2522 2311 * … … 2524 2313 * screen is certain to need. Two cases qualify today: 2525 2314 * 2526 * - The login screen, which is followed by an admin screen. With concatenation disabled that2527 * screen downloads each core script and stylesheet separately, which is what makes an uncached2528 * admin load slower than a concatenated one. Requesting the ones that block its first paint2529 * while the login form is on screen puts them in the HTTP cache during the time the user spends2530 * typing credentials, so the redirect that follows finds themalready 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. 2531 2320 * - The Dashboard and the post list tables, from which the editor is the usual next stop. Only the 2532 2321 * editor's stylesheets are prefetched, not its scripts: the scripts run to well over a megabyte … … 2560 2349 * printed at all when `redirect_to` points outside this site's admin. 2561 2350 * 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 *2565 2351 * @since 7.2.0 2566 2352 * 2567 2353 * @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. 2572 2356 */ 2573 2357 function wp_prefetch_admin_assets(): void { 2574 global $c oncatenate_scripts, $current_screen;2358 global $current_screen; 2575 2359 2576 2360 /* 2577 2361 * The context is told apart by the request rather than by the hook this runs on, so it works 2578 2362 * 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. 2583 2366 */ 2584 2367 $on_login = (bool) did_action( 'login_init' ); 2585 2368 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 ) { 2598 2370 /* 2599 2371 * From the Dashboard and the post list tables, the editor is the usual next stop. Anywhere … … 2605 2377 */ 2606 2378 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 editor2612 * will be served the same way.2613 */2614 script_concat_settings();2615 2616 if ( $concatenate_scripts ) {2617 2379 return; 2618 2380 } -
trunk/tests/phpstan/base.neon
r64486 r64585 213 213 excludePaths: 214 214 analyseAndScan: 215 - ../../src/wp-admin/includes/noop.php216 215 # Locally installed npm dependencies, such as in bundled themes, which may include PHP files. 217 216 - */node_modules/* … … 225 224 - ../../src/wp-includes/ms-deprecated.php 226 225 - ../../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.php229 - ../../src/wp-admin/load-styles.php230 226 # These files are autogenerated by tools/gutenberg/copy.js. 231 227 - ../../src/wp-includes/blocks -
trunk/tests/phpstan/baselines/variable.undefined.neon
r64582 r64585 785 785 path: ../../../src/wp-includes/ms-settings.php 786 786 - 787 message: '#^Variable \$wp_version might not be defined\.$#'788 identifier: variable.undefined789 count: 2790 path: ../../../src/wp-includes/script-loader.php791 -792 787 message: '#^Variable \$wp_template_path might not be defined\.$#' 793 788 identifier: variable.undefined -
trunk/tests/phpunit/tests/dependencies.php
r64040 r64585 177 177 * @ticket 58433 178 178 * @ticket 61485 179 * @ticket 57548 179 180 * 180 181 * @covers WP_Dependencies::get_etag 182 * 183 * @expectedDeprecated WP_Dependencies::get_etag 181 184 * 182 185 * @dataProvider data_provider_get_etag … … 211 214 * @ticket 58433 212 215 * @ticket 61485 216 * @ticket 57548 213 217 * 214 218 * @covers WP_Dependencies::get_etag 219 * 220 * @expectedDeprecated WP_Dependencies::get_etag 215 221 * 216 222 * @dataProvider data_provider_get_etag -
trunk/tests/phpunit/tests/dependencies/scriptConcatSettings.php
r64485 r64585 57 57 58 58 /** 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 /** 59 74 * Tests that the compression globals default to false, as scripts and styles are not compressed from PHP. 60 75 * 61 76 * @ticket 63017 77 * 78 * @expectedDeprecated script_concat_settings 62 79 */ 63 80 public function test_compression_globals_default_to_false(): void { … … 75 92 * 76 93 * @ticket 63017 94 * 95 * @expectedDeprecated script_concat_settings 77 96 * 78 97 * @runInSeparateProcess … … 94 113 * 95 114 * @ticket 63017 115 * 116 * @expectedDeprecated script_concat_settings 96 117 */ 97 118 public function test_compression_globals_already_set_are_kept(): void { -
trunk/tests/phpunit/tests/dependencies/scripts.php
r64485 r64585 26 26 class Tests_Dependencies_Scripts extends WP_UnitTestCase { 27 27 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; 42 31 43 32 protected $wp_scripts_print_translations_output; … … 52 41 public function set_up() { 53 42 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; 57 47 remove_action( 'wp_default_scripts', 'wp_default_scripts' ); 58 48 remove_action( 'wp_default_scripts', 'wp_default_packages' ); … … 62 52 63 53 $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-translations71 </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; 73 63 $this->wp_scripts_print_translations_output .= "\n"; 74 64 } 75 65 76 66 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; 80 69 add_action( 'wp_default_scripts', 'wp_default_scripts' ); 81 70 parent::tear_down(); … … 423 412 $output = get_echo( 'wp_print_scripts' ); 424 413 $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; 429 418 $this->assertEqualHTML( $expected, $output, '<body>', 'Blocking dependents must force delayed dependencies to become blocking.' ); 430 419 } … … 673 662 }, 674 663 '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, 701 683 ), 702 684 'async-with-async-dependencies' => array( … … 714 696 }, 715 697 '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, 745 726 ), 746 727 'async-with-blocking-dependency' => array( … … 756 737 }, 757 738 '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, 778 758 ), 779 759 'defer-with-async-dependency' => array( … … 789 769 }, 790 770 '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, 811 790 ), 812 791 'blocking-bundle-of-none-with-inline-scripts-and-defer-dependent' => array( … … 825 804 }, 826 805 '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, 846 824 ), 847 825 'blocking-bundle-of-two-with-defer-dependent' => array( … … 863 841 }, 864 842 '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, 894 871 ), 895 872 'defer-bundle-of-none-with-inline-scripts-and-defer-dependents' => array( … … 910 887 }, 911 888 '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, 931 907 ), 932 908 'defer-dependent-with-blocking-and-defer-dependencies' => array( … … 945 921 }, 946 922 '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, 976 951 ), 977 952 'defer-dependent-with-defer-and-blocking-dependencies' => array( … … 990 965 }, 991 966 '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, 1021 995 ), 1022 996 'async-with-defer-dependency' => array( … … 1032 1006 }, 1033 1007 '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, 1054 1027 ), 1055 1028 'defer-with-before-inline-script' => array( … … 1061 1034 }, 1062 1035 '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, 1070 1042 ), 1071 1043 'defer-with-after-inline-script' => array( … … 1077 1049 }, 1078 1050 '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, 1086 1057 ), 1087 1058 'jquery-deferred' => array( … … 1096 1067 }, 1097 1068 '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, 1103 1073 ), 1104 1074 'nested-aliases' => array( … … 1121 1091 }, 1122 1092 '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, 1137 1106 ), 1138 1107 … … 1150 1119 }, 1151 1120 '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, 1157 1125 ), 1158 1126 ); … … 1736 1704 $actual = get_echo( 'wp_print_scripts' ); 1737 1705 $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; 1748 1716 $this->assertEqualHTML( $expected, $actual, '<body>', "Snapshot:\n$actual" ); 1749 1717 } … … 2164 2132 2165 2133 /** 2166 * Tests that scripts registered with a deferred strategy are not included in the script concat loading query.2167 *2168 * @ticket 120092169 *2170 * @covers WP_Scripts::do_item2171 * @covers ::wp_enqueue_script2172 * @covers ::wp_register_script2173 *2174 * @global WP_Scripts $wp_scripts2175 * @global bool $concatenate_scripts2176 * @global string $wp_version2177 */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&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 120092204 *2205 * @covers WP_Scripts::do_item2206 * @covers ::wp_enqueue_script2207 * @covers ::wp_register_script2208 *2209 * @global WP_Scripts $wp_scripts2210 * @global bool $concatenate_scripts2211 * @global string $wp_version2212 */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&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 blocking2237 * scripts are registered.2238 *2239 * @ticket 120092240 *2241 * @covers WP_Scripts::do_item2242 * @covers ::wp_enqueue_script2243 * @covers ::wp_register_script2244 *2245 * @global WP_Scripts $wp_scripts2246 * @global bool $concatenate_scripts2247 * @global string $wp_version2248 */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&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 /**2275 2134 * Test the different protocol references in wp_enqueue_script 2276 2135 * … … 2318 2177 2319 2178 /** 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 2321 2184 * 2322 2185 * @global WP_Scripts $wp_scripts 2323 * @global string $wp_version2324 */ 2325 public function test_ script_concatenation(){2186 * @global string $wp_version 2187 */ 2188 public function test_do_concat_is_ignored(): void { 2326 2189 global $wp_scripts, $wp_version; 2327 2190 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&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.' ); 2341 2277 } 2342 2278 … … 2587 2523 2588 2524 $expected = <<<HTML 2589 <script id='test-example-js-before'>2590 console.log("before");2591 //# sourceURL=test-example-js-before2592 </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; 2595 2531 $expected .= "<script src='http://example.com' id='test-example-js'></script>\n"; 2596 2532 … … 2607 2543 $expected = "<script src='http://example.com' id='test-example-js'></script>\n"; 2608 2544 $expected .= <<<HTML 2609 <script id='test-example-js-after'>2610 console.log("after");2611 //# sourceURL=test-example-js-after2612 </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; 2615 2551 2616 2552 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); … … 2703 2639 $expected .= "<script src='http://example.com' id='test-example-js'></script>\n"; 2704 2640 $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 148532711 */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 148532736 */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 148532759 *2760 * @global WP_Scripts $wp_scripts2761 * @global string $wp_version2762 */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&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 148532791 * @ticket 638212792 */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 363922816 *2817 * @global WP_Scripts $wp_scripts2818 * @global string $wp_version2819 */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&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 363922845 * @ticket 638212846 */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 363922867 *2868 * @global WP_Scripts $wp_scripts2869 * @global string $wp_version2870 */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&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 363922895 *2896 * @global WP_Scripts $wp_scripts2897 * @global string $wp_version2898 */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&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 363922950 */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 363922983 */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 363923007 *3008 * @global WP_Scripts $wp_scripts3009 * @global string $wp_version3010 */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&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";3027 2641 3028 2642 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); … … 3819 3433 3820 3434 /** 3821 * @ticket 556283822 *3823 * @covers ::wp_set_script_translations3824 *3825 * @global WP_Scripts $wp_scripts3826 * @global string $wp_version3827 */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&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 /**3858 3435 * Ensure tinymce scripts aren't loading async. 3859 3436 * … … 3875 3452 * 3876 3453 * @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 { 3887 3456 $wp_scripts = wp_scripts(); 3888 3457 wp_register_tinymce_scripts( $wp_scripts ); … … 3898 3467 $this->assertMatchesRegularExpression( '#/js/tinymce/plugins/compat3x/plugin(\.min)?\.js$#', $tinymce->src ); 3899 3468 $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 );3916 3469 } 3917 3470 … … 4401 3954 4402 3955 $expected = <<<HTML 4403 <script id="# test/</script> #-js-extra">4404 var test = [];4405 //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-extra4406 </script>4407 <script id="# test/</script> #-js-before">4408 "before";4409 //# sourceURL=%23%20test%2F%3C%2Fscript%3E%20%23-js-before4410 </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-after4415 </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; 4418 3971 4419 3972 $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) ); 4420 }4421 4422 /**4423 * @ticket 638874424 *4425 * @global WP_Scripts $wp_scripts4426 * @global bool $concatenate_scripts4427 * @global string $wp_version4428 */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 = <<<HTML4446 <script>4447 var one = {"key":"val"};var two = {"key":"val"};4448 //# sourceURL=js-inline-concat-one%2Ctwo4449 </script>4450 <script src="/wp-admin/load-scripts.php?load%5Bchunk_0%5D=one,two&ver={$wp_version}"></script>4451 4452 HTML;4453 4454 $this->assertEqualHTML( $expected, $print_scripts );4455 3973 } 4456 3974 -
trunk/tests/phpunit/tests/dependencies/styles.php
r64485 r64585 10 10 */ 11 11 class 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; 14 15 15 16 public function set_up() { 16 17 parent::set_up(); 17 18 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; 29 23 30 24 remove_action( 'wp_default_styles', 'wp_default_styles' ); … … 199 193 200 194 /** 201 * Test if inline styles work with concatenation195 * Tests that inline styles are printed right away when the deprecated `do_concat` property is set. 202 196 * 203 197 * @global WP_Styles $wp_styles 204 198 * @ticket 24813 199 * @ticket 57548 205 200 */ 206 201 public function test_inline_styles_concat() { 207 202 global $wp_styles; 208 203 209 $wp_styles->do_concat = true;210 $wp_styles->d efault_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; 211 206 212 207 $style = ".thing {\n"; … … 217 212 $expected .= "<style id='handle-inline-css'>\n"; 218 213 $expected .= "$style\n"; 214 $expected .= "/*# sourceURL=handle-inline-css */\n"; 219 215 $expected .= "</style>\n"; 220 216 … … 222 218 wp_add_inline_style( 'handle', $style ); 223 219 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' ) ); 226 262 } 227 263 … … 899 935 900 936 $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; 908 944 909 945 $this->assertEqualHTML( $expected, get_echo( 'wp_print_styles' ) ); 910 }911 912 /**913 * @ticket 63887914 *915 * @global WP_Styles $wp_styles916 * @global string $wp_version917 */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 = <<<HTML934 <link935 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 );947 946 } 948 947 -
trunk/tests/phpunit/tests/dependencies/wpPrefetchAdminAssets.php
r64121 r64585 2 2 /** 3 3 * Tests for {@see wp_prefetch_admin_assets()}. 4 *5 * Prefetching only happens when concatenation is off. Each test turns it off with the6 * {@see 'wp_should_concatenate_admin_scripts'} filter, so that it does not depend on the7 * `CONCATENATE_SCRIPTS` and `SCRIPT_DEBUG` constants, which cannot be changed once defined.8 4 * 9 5 * @package WordPress … … 32 28 33 29 /** 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. 36 31 */ 37 32 public function set_up(): void { … … 44 39 45 40 $this->original_script_name = $_SERVER['SCRIPT_NAME'] ?? null; 46 47 add_filter( 'wp_should_concatenate_admin_scripts', '__return_false' );48 41 } 49 42 … … 70 63 71 64 /** 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. 86 67 * 87 68 * @ticket 57548 … … 90 71 $GLOBALS['concatenate_scripts'] = true; 91 72 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 { 107 83 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); 108 84 109 85 $GLOBALS['concatenate_scripts'] = true; 110 86 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' ) ); 131 89 } 132 90
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)