From 3109e8211f0acf0db2141c3cb7b31d9e083d9a87 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 4 Dec 2018 02:11:44 +0000 Subject: [PATCH] Scripts: Ensure sub-directory WordPress installs can load polyfill scripts. `wp_get_script_polyfill()` bypasses `WP_Scripts::do_item()`, so didn't transform the script path into its fully qualified URL. Props swissspidy, ocean90. See #45469. Built from https://develop.svn.wordpress.org/branches/5.0@43960 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43792 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/script-loader.php | 20 +++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index b21f9a6f49..9316d70811 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -178,6 +178,24 @@ function wp_get_script_polyfill( &$scripts, $tests ) { continue; } + $src = $scripts->registered[ $handle ]->src; + $ver = $scripts->registered[ $handle ]->ver; + + if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && 0 === strpos( $src, $scripts->content_url ) ) ) { + $src = $scripts->base_url . $src; + } + + if ( ! empty( $ver ) ) { + $src = add_query_arg( 'ver', $ver, $src ); + } + + /** This filter is documented in wp-includes/class.wp-scripts.php */ + $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); + + if ( ! $src ) { + continue; + } + $polyfill .= ( // Test presence of feature... '( ' . $test . ' ) || ' . @@ -185,7 +203,7 @@ function wp_get_script_polyfill( &$scripts, $tests ) { // at the `document.write`. Its caveat of synchronous mid-stream // blocking write is exactly the behavior we need though. 'document.write( \'