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

Properly make URLs relative when using multisite with domain mapping & use parse_url function instead of regex for parsing URLs #91

Merged
merged 2 commits into from
May 15, 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
9 changes: 6 additions & 3 deletions lib/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
* Make a URL relative
*/
function root_relative_url($input) {
preg_match('|(?:https?:)?//([^/]+)(/.*)|i', $input, $matches);
if (!isset($matches[1]) || !isset($matches[2])) {
$url = parse_url($input);
if (!isset($url['host']) || !isset($url['path'])) {
return $input;
}
if (($matches[1] === $_SERVER['SERVER_NAME']) || $matches[1] === $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) {
if (is_multisite()) {
$network_url = parse_url(network_site_url(), PHP_URL_HOST);
}
if (($url['host'] === $_SERVER['SERVER_NAME']) || $url['host'] === $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] || (isset($network_url) && $url['host'] === $network_url)) {
return wp_make_link_relative($input);
}
return $input;
Expand Down