Skip to content

Commit

Permalink
Preserve Home URL scheme when fetching Sitemap for Auto-Cache Engine
Browse files Browse the repository at this point in the history
See websharks/cometcache.com#715
  • Loading branch information
raamdev committed Apr 6, 2016
1 parent 1bdbb4b commit 76e037b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/includes/classes/AutoCache.php
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions src/includes/traits/Plugin/UrlUtils.php
Expand Up @@ -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;
}
}

0 comments on commit 76e037b

Please sign in to comment.