Skip to content

Commit

Permalink
Scripts: Ensure sub-directory WordPress installs can load polyfill sc…
Browse files Browse the repository at this point in the history
…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 0cea68e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/wp-includes/script-loader.php
Expand Up @@ -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>\' );'
);
}
Expand Down

0 comments on commit 0cea68e

Please sign in to comment.