diff --git a/src/AssetsController.php b/src/AssetsController.php index cf1e3260a3e..85990ba61b8 100644 --- a/src/AssetsController.php +++ b/src/AssetsController.php @@ -163,7 +163,7 @@ private function get_script_dependency_src_array( array $dependencies ) { $dependencies, function( $src, $handle ) use ( $wp_scripts ) { if ( isset( $wp_scripts->registered[ $handle ] ) ) { - $src[] = add_query_arg( 'ver', $wp_scripts->registered[ $handle ]->ver, $wp_scripts->registered[ $handle ]->src ); + $src[] = add_query_arg( 'ver', $wp_scripts->registered[ $handle ]->ver, $this->get_absolute_url( $wp_scripts->registered[ $handle ]->src ) ); $src = array_merge( $src, $this->get_script_dependency_src_array( $wp_scripts->registered[ $handle ]->deps ) ); } return $src; @@ -172,6 +172,20 @@ function( $src, $handle ) use ( $wp_scripts ) { ); } + /** + * Returns an absolute url to relative links for WordPress core scripts. + * + * @param string $src Original src that can be relative. + * @return string Correct full path string. + */ + private function get_absolute_url( $src ) { + $wp_scripts = wp_scripts(); + if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) { + $src = $wp_scripts->base_url . $src; + } + return $src; + } + /** * Add body classes to the frontend and within admin. *