roots_relative_urls now ignores external links
This commit is contained in:
@@ -54,32 +54,37 @@ 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 ); }
|
||||
|
||||
$primary_nav = wp_get_nav_menu_object('Primary Navigation');
|
||||
|
||||
$primary_nav_term_id = (int) $primary_nav->term_id;
|
||||
$menu_items= wp_get_nav_menu_items($primary_nav_term_id);
|
||||
if(!$menu_items || empty($menu_items)){
|
||||
$pages = get_pages();
|
||||
foreach($pages as $page) {
|
||||
$item = array(
|
||||
'menu-item-object-id' => $page->ID,
|
||||
'menu-item-object' => 'page',
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-status' => 'publish'
|
||||
);
|
||||
wp_update_nav_menu_item($primary_nav_term_id, 0, $item);
|
||||
}
|
||||
}
|
||||
if ($roots_nav_theme_mod) {
|
||||
set_theme_mod('nav_menu_locations', $roots_nav_theme_mod );
|
||||
}
|
||||
|
||||
$primary_nav = wp_get_nav_menu_object('Primary Navigation');
|
||||
|
||||
$primary_nav_term_id = (int) $primary_nav->term_id;
|
||||
$menu_items= wp_get_nav_menu_items($primary_nav_term_id);
|
||||
if (!$menu_items || empty($menu_items)) {
|
||||
$pages = get_pages();
|
||||
foreach($pages as $page) {
|
||||
$item = array(
|
||||
'menu-item-object-id' => $page->ID,
|
||||
'menu-item-object' => 'page',
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-status' => 'publish'
|
||||
);
|
||||
wp_update_nav_menu_item($primary_nav_term_id, 0, $item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,13 @@ 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);
|
||||
return str_replace(end($matches), '', $input);
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user