roots_relative_urls now ignores external links

This commit is contained in:
Scott Walkinshaw
2011-06-07 16:33:29 -06:00
parent b218fc2d75
commit 9260044ed4
2 changed files with 29 additions and 19 deletions

View File

@@ -54,15 +54,20 @@ if (is_admin() && 'themes.php' === $pagenow && isset( $_GET['activated'])) {
// automatically create menus and set their locations
// add all pages to the Primary Navigation
$roots_nav_theme_mod = false;
if (!has_nav_menu('primary_navigation')) {
$primary_nav_id = wp_create_nav_menu('Primary Navigation', array('slug' => 'primary_navigation'));
$roots_nav_theme_mod['primary_navigation'] = $primary_nav_id;
}
if (!has_nav_menu('utility_navigation')) {
$utility_nav_id = wp_create_nav_menu('Utility Navigation', array('slug' => 'utility_navigation'));
$roots_nav_theme_mod['utility_navigation'] = $utility_nav_id;
}
if ($roots_nav_theme_mod) { set_theme_mod('nav_menu_locations', $roots_nav_theme_mod ); }
if ($roots_nav_theme_mod) {
set_theme_mod('nav_menu_locations', $roots_nav_theme_mod );
}
$primary_nav = wp_get_nav_menu_object('Primary Navigation');

View File

@@ -76,9 +76,14 @@ add_filter('get_search_query', 'roots_search_query');
// inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/
// thanks to Scott Walkinshaw (scottwalkinshaw.com)
function roots_root_relative_url($input) {
preg_match('/(https?:\/\/[^\/]+)/', $input, $matches);
preg_match('/(https?:\/\/[^\/|"]+)/', $input, $matches);
// make sure we aren't making external links relative
if (strpos($matches[0], site_url()) === false) {
return $input;
} else {
return str_replace(end($matches), '', $input);
}
}
add_filter('bloginfo_url', 'roots_root_relative_url');
add_filter('theme_root_uri', 'roots_root_relative_url');