Skip to content
Permalink
Browse files

Scripts: Ensure sub-directory WordPress installs can load polyfill sc…

…ripts.

`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.


git-svn-id: https://develop.svn.wordpress.org/branches/5.0@43960 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
pento committed Dec 4, 2018
1 parent d09e22f commit 0cea68e9e6e0eeb77367c6a7f253bd3356b70f94
Showing with 19 additions and 1 deletion.
  1. +19 −1 src/wp-includes/script-loader.php
@@ -178,14 +178,32 @@ 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 . ' ) || ' .
// ...appending polyfill on any failures. Cautious viewers may balk
// at the `document.write`. Its caveat of synchronous mid-stream
// blocking write is exactly the behavior we need though.
'document.write( \'<script src="' .
esc_url( $scripts->registered[ $handle ]->src ) .
$src .
'"></scr\' + \'ipt>\' );'
);
}

0 comments on commit 0cea68e

Please sign in to comment.
You can’t perform that action at this time.