Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Refactored root_relative_url() #94

Merged
merged 1 commit into from
May 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ function root_relative_url($input) {
if (!isset($url['host']) || !isset($url['path'])) {
return $input;
}
if (is_multisite()) {
$network_url = parse_url(network_site_url(), PHP_URL_HOST);
$site_url = parse_url(network_site_url()); // falls back to site_url

if (!isset($url['scheme'])) {
$url['scheme'] = $site_url['scheme'];
}
if (($url['host'] === $_SERVER['SERVER_NAME']) || $url['host'] === $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] || (isset($network_url) && $url['host'] === $network_url)) {
$hosts_match = $site_url['host'] === $url['host'];
$schemes_match = $site_url['scheme'] === $url['scheme'];
$ports_exist = isset($site_url['port']) && isset($url['port']);
$ports_match = ($ports_exist) ? $site_url['port'] === $url['port'] : true;

if ($hosts_match && $schemes_match && $ports_match) {
return wp_make_link_relative($input);
}
return $input;
Expand Down