Make WordPress Core

Ticket #45528: 45528.3.patch

File 45528.3.patch, 2.4 KB (added by akirk, 6 years ago)

Add support for CDNs that mirror all static assets

  • src/wp-includes/l10n.php

     
    900900
    901901        $obj = $wp_scripts->registered[ $handle ];
    902902
     903        $src = $obj->src;
     904        if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
     905                $src = $wp_scripts->base_url . $src;
     906        }
    903907        /** This filter is documented in wp-includes/class.wp-scripts.php */
    904         $src = esc_url( apply_filters( 'script_loader_src', $obj->src, $handle ) );
     908        $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
    905909
    906910        $relative       = false;
    907911        $languages_path = WP_LANG_DIR;
     
    913917        // If the host is the same or it's a relative URL.
    914918        if (
    915919                strpos( $src_url['path'], $content_url['path'] ) === 0 &&
    916                 ( ! isset( $src_url['host'] ) || $src_url['host'] !== $content_url['host'] )
     920                ( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] )
    917921        ) {
    918922                // Make the src relative the specific plugin or theme.
    919                 $relative = trim( substr( $src, strlen( $content_url['path'] ) ), '/' );
     923                $relative = trim( substr( $src_url['path'], strlen( $content_url['path'] ) ), '/' );
    920924                $relative = explode( '/', $relative );
    921925
    922926                $languages_path = WP_LANG_DIR . '/' . $relative[0];
    923927
    924928                $relative = array_slice( $relative, 2 );
    925929                $relative = implode( '/', $relative );
    926         } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) {
     930        } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) {
    927931                if ( ! isset( $site_url['path'] ) ) {
    928932                        $relative = trim( $src_url['path'], '/' );
    929                 } elseif ( ( strpos( $src_url['path'], $site_url['path'] ) === 0 ) ) {
     933                } elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) {
    930934                        // Make the src relative to the WP root.
    931                         $relative = substr( $src, strlen( $site_url['path'] ) );
     935                        $relative = substr( $src_url['path'], strlen( $site_url['path'] ) );
    932936                        $relative = trim( $relative, '/' );
    933937                }
     938        } elseif ( isset( $src_url['host'] ) && $src_url['host'] !== $site_url['host'] && false !== strpos( $src_url['path'], '/wp-includes/' ) ) {
     939                // This handles CDNs that mirror all static assets.
     940                $relative = substr( $src_url['path'], 1 + strpos( $src_url['path'], '/wp-includes/' ) );
    934941        }
    935942
    936943        // If the source is not from WP.