From 5548ab1e975211434a2e9d01e71b4f80a3b5775a Mon Sep 17 00:00:00 2001 From: Luigi Date: Mon, 11 Jul 2022 14:16:55 +0200 Subject: [PATCH 1/2] Fix loading deps when WordPress is installed in a subdir #6500 Fix loading deps when WordPress is installed in a subdir --- src/BlockTypes/MiniCart.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/BlockTypes/MiniCart.php b/src/BlockTypes/MiniCart.php index 80e9330ce40..8028cfd985a 100644 --- a/src/BlockTypes/MiniCart.php +++ b/src/BlockTypes/MiniCart.php @@ -276,8 +276,12 @@ protected function append_script_and_deps_src( $script ) { if ( ! $script->src ) { return; } + + $site_url = get_site_url(); + $path = wp_parse_url( $site_url )['path'] ?? ''; + $this->scripts_to_lazy_load[ $script->handle ] = array( - 'src' => $script->src, + 'src' => wp_http_validate_url( $script->src ) ? $script->src : $path . $script->src, 'version' => $script->ver, 'before' => $wp_scripts->print_inline_script( $script->handle, 'before', false ), 'after' => $wp_scripts->print_inline_script( $script->handle, 'after', false ), From 84ec912f3846821026a58792b151aa8e1a6762ab Mon Sep 17 00:00:00 2001 From: Luigi Date: Wed, 13 Jul 2022 10:27:10 +0200 Subject: [PATCH 2/2] update logic --- src/BlockTypes/MiniCart.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/BlockTypes/MiniCart.php b/src/BlockTypes/MiniCart.php index 8028cfd985a..53a0f91d891 100644 --- a/src/BlockTypes/MiniCart.php +++ b/src/BlockTypes/MiniCart.php @@ -277,11 +277,10 @@ protected function append_script_and_deps_src( $script ) { return; } - $site_url = get_site_url(); - $path = wp_parse_url( $site_url )['path'] ?? ''; + $site_url = site_url() ?? wp_guess_url(); $this->scripts_to_lazy_load[ $script->handle ] = array( - 'src' => wp_http_validate_url( $script->src ) ? $script->src : $path . $script->src, + 'src' => preg_match( '|^(https?:)?//|', $script->src ) ? $script->src : $site_url . $script->src, 'version' => $script->ver, 'before' => $wp_scripts->print_inline_script( $script->handle, 'before', false ), 'after' => $wp_scripts->print_inline_script( $script->handle, 'after', false ),