Make WordPress Core

Changeset 43960


Ignore:
Timestamp:
12/04/2018 02:10:44 AM (6 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/script-loader.php

    r43955 r43960  
    179179        }
    180180
     181        $src = $scripts->registered[ $handle ]->src;
     182        $ver = $scripts->registered[ $handle ]->ver;
     183
     184        if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && 0 === strpos( $src, $scripts->content_url ) ) ) {
     185            $src = $scripts->base_url . $src;
     186        }
     187
     188        if ( ! empty( $ver ) ) {
     189            $src = add_query_arg( 'ver', $ver, $src );
     190        }
     191
     192        /** This filter is documented in wp-includes/class.wp-scripts.php */
     193        $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
     194
     195        if ( ! $src ) {
     196            continue;
     197        }
     198
    181199        $polyfill .= (
    182200            // Test presence of feature...
     
    186204            // blocking write is exactly the behavior we need though.
    187205            'document.write( \'<script src="' .
    188             esc_url( $scripts->registered[ $handle ]->src ) .
     206            $src .
    189207            '"></scr\' + \'ipt>\' );'
    190208        );
Note: See TracChangeset for help on using the changeset viewer.