Better rewrite/clean URL handling
- New roots-utils.php file for base functions - Defined useful constants for dealing with common paths - Refactored rewrites and clean URLs to be more flexible for non standard setups - Custom scripts handler now deals with plugin scripts correctly - Fixes #204, #270, #278
This commit is contained in:
@@ -52,40 +52,31 @@ function roots_root_relative_url($input) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Terrible workaround to remove the duplicate subfolder in the src of JS/CSS tags
|
||||
// Example: /subfolder/subfolder/css/style.css
|
||||
function roots_fix_duplicate_subfolder_urls($input) {
|
||||
$output = roots_root_relative_url($input);
|
||||
preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);
|
||||
if (isset($matches[1]) && isset($matches[2])) {
|
||||
if ($matches[1][0] === $matches[2][0]) {
|
||||
$output = substr($output, strlen($matches[1][0]) + 1);
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (!is_admin() && !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) {
|
||||
add_filter('bloginfo_url', 'roots_root_relative_url');
|
||||
add_filter('theme_root_uri', 'roots_root_relative_url');
|
||||
add_filter('stylesheet_directory_uri', 'roots_root_relative_url');
|
||||
add_filter('template_directory_uri', 'roots_root_relative_url');
|
||||
add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
|
||||
add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
|
||||
add_filter('plugins_url', 'roots_root_relative_url');
|
||||
add_filter('the_permalink', 'roots_root_relative_url');
|
||||
add_filter('wp_list_pages', 'roots_root_relative_url');
|
||||
add_filter('wp_list_categories', 'roots_root_relative_url');
|
||||
add_filter('wp_nav_menu', 'roots_root_relative_url');
|
||||
add_filter('the_content_more_link', 'roots_root_relative_url');
|
||||
add_filter('the_tags', 'roots_root_relative_url');
|
||||
add_filter('get_pagenum_link', 'roots_root_relative_url');
|
||||
add_filter('get_comment_link', 'roots_root_relative_url');
|
||||
add_filter('month_link', 'roots_root_relative_url');
|
||||
add_filter('day_link', 'roots_root_relative_url');
|
||||
add_filter('year_link', 'roots_root_relative_url');
|
||||
add_filter('tag_link', 'roots_root_relative_url');
|
||||
add_filter('the_author_posts_link', 'roots_root_relative_url');
|
||||
$tags = array(
|
||||
'bloginfo_url',
|
||||
'theme_root_uri',
|
||||
'stylesheet_directory_uri',
|
||||
'template_directory_uri',
|
||||
'script_loader_src',
|
||||
'style_loader_src',
|
||||
'plugins_url',
|
||||
'the_permalink',
|
||||
'wp_list_pages',
|
||||
'wp_list_categories',
|
||||
'wp_nav_menu',
|
||||
'the_content_more_link',
|
||||
'the_tags',
|
||||
'get_pagenum_link',
|
||||
'get_comment_link',
|
||||
'month_link',
|
||||
'day_link',
|
||||
'year_link',
|
||||
'tag_link',
|
||||
'the_author_posts_link'
|
||||
);
|
||||
|
||||
add_filters($tags, 'roots_root_relative_url');
|
||||
}
|
||||
|
||||
// remove root relative URLs on any attachments in the feed
|
||||
@@ -667,4 +658,4 @@ if (class_exists('RGForms')) {
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user