WordPress.org

Make WordPress Core

Changeset 44286


Ignore:
Timestamp:
12/18/2018 04:04:21 AM (8 months ago)
Author:
SergeyBiryukov
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.
Merges [43960] to trunk.
Fixes #45469.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/script-loader.php

    r44281 r44286  
    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.