Migrate @Foxaii's nav-rejig for 8.0.0

This commit is contained in:
Ben Word
2015-02-12 23:11:36 -06:00
parent 91a1944af8
commit 17a04ee696
2 changed files with 83 additions and 28 deletions

View File

@@ -24,3 +24,38 @@ function body_class($classes) {
return $classes;
}
add_filter('body_class', __NAMESPACE__ . '\\body_class');
/**
* Make a URL relative
*/
function root_relative_url($input) {
preg_match('|https?://([^/]+)(/.*)|i', $input, $matches);
if (!isset($matches[1]) || !isset($matches[2])) {
return $input;
} elseif (($matches[1] === $_SERVER['SERVER_NAME']) || $matches[1] === $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) {
return wp_make_link_relative($input);
} else {
return $input;
}
}
/**
* Compare URL against relative URL
*/
function url_compare($url, $rel) {
$url = trailingslashit($url);
$rel = trailingslashit($rel);
if ((strcasecmp($url, $rel) === 0) || root_relative_url($url) == $rel) {
return true;
} else {
return false;
}
}
/**
* Check if element is empty
*/
function is_element_empty($element) {
$element = trim($element);
return !empty($element);
}