diff --git a/src/includes/classes/AutoCache.php b/src/includes/classes/AutoCache.php index 80328fef..7575b77d 100644 --- a/src/includes/classes/AutoCache.php +++ b/src/includes/classes/AutoCache.php @@ -88,10 +88,10 @@ protected function run() $_blog_sitemap_urls = $_blog_other_urls = $_blog_urls = []; if (!isset($_blog->ID)) { // `home_url()` fallback. - $_blog_url = rtrim(network_home_url('', 'http'), '/'); + $_blog_url = rtrim($this->plugin->getHomeUrlWithHomeScheme(), '/'); $this->is_child_blog = false; // Simple flag. } else { // This calls upon `switch_to_blog()` to acquire. - $_blog_url = rtrim(get_home_url($_blog->ID, '', 'http'), '/'); + $_blog_url = rtrim($this->plugin->getHomeUrlWithHomeScheme($_blog->ID), '/'); $this->is_child_blog = true; // Simple flag; yes it is! } if ($is_multisite && $can_consider_domain_mapping) { diff --git a/src/includes/traits/Plugin/UrlUtils.php b/src/includes/traits/Plugin/UrlUtils.php index 0af823ac..de947d6b 100644 --- a/src/includes/traits/Plugin/UrlUtils.php +++ b/src/includes/traits/Plugin/UrlUtils.php @@ -25,4 +25,28 @@ public function url($file = '', $scheme = '') } return $url; } + + /** + * Retrieves the home URL for a given site preserving the home URL scheme. + * + * @since 16xxxx Improving Auto-Cache Engine Sitemap routines. + * + * @param int $blog_id (Optional) Blog ID. Default null (current blog). + * + * @return string $url Home URL link with Home URL scheme preserved. + */ + public function getHomeUrlWithHomeScheme($blog_id = null) + { + if (empty($blog_id) || !is_multisite()) { + $url = get_option('home'); + } else { + switch_to_blog($blog_id); + $url = get_option('home'); + restore_current_blog(); + } + + $url = set_url_scheme($url, parse_url($url, PHP_URL_SCHEME)); + + return $url; + } }