From 8e9696592a2854052609fff83e0fb35c9ea5d3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20S=C3=B8derlind?= Date: Wed, 23 Aug 2023 16:31:47 +0200 Subject: [PATCH 1/3] See https://core.trac.wordpress.org/ticket/59173 --- src/wp-includes/link-template.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index c0437f6de9ff1..b8be682ccf116 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -3495,9 +3495,15 @@ function get_site_url( $blog_id = null, $path = '', $scheme = null ) { if ( empty( $blog_id ) || ! is_multisite() ) { $url = get_option( 'siteurl' ); } else { - switch_to_blog( $blog_id ); - $url = get_option( 'siteurl' ); - restore_current_blog(); + // Use WP_Site_Query to get the site URL. + $site = get_site( $blog_id ); + + $url = $site->domain . $site->path; + + // If the network has a custom domain, use that instead. + if ( $site->domain !== \get_network()->domain ) { + $url = get_network()->domain . $site->path; + } } $url = set_url_scheme( $url, $scheme ); From ab088f2778cf0df6133e6004a1ed34ee38189f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20S=C3=B8derlind?= Date: Wed, 23 Aug 2023 16:41:53 +0200 Subject: [PATCH 2/3] Yoda I must --- src/wp-includes/link-template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index b8be682ccf116..105b4f97859ce 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -3501,7 +3501,7 @@ function get_site_url( $blog_id = null, $path = '', $scheme = null ) { $url = $site->domain . $site->path; // If the network has a custom domain, use that instead. - if ( $site->domain !== \get_network()->domain ) { + if ( \get_network()->domain !== $site->domain ) { $url = get_network()->domain . $site->path; } } From e22114056b3b6f5cd526ffe8ca4a49ad6a7d2a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20S=C3=B8derlind?= Date: Wed, 23 Aug 2023 17:43:16 +0200 Subject: [PATCH 3/3] Remove backslash from function --- src/wp-includes/link-template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 105b4f97859ce..3541e9105bd3a 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -3501,7 +3501,7 @@ function get_site_url( $blog_id = null, $path = '', $scheme = null ) { $url = $site->domain . $site->path; // If the network has a custom domain, use that instead. - if ( \get_network()->domain !== $site->domain ) { + if ( get_network()->domain !== $site->domain ) { $url = get_network()->domain . $site->path; } }