From 909adf7fdca945b2ce839aba193357940436121c Mon Sep 17 00:00:00 2001 From: Seghir Nadir Date: Fri, 23 Sep 2022 12:02:05 +0100 Subject: [PATCH] use full link for WordPress resources (#7211) Co-authored-by: Niels Lange --- src/AssetsController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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. *