Restore duplicate subfolder removal

This commit is contained in:
Scott Walkinshaw
2012-04-10 21:05:52 -04:00
parent 060ab1bea5
commit 69a42d05df

View File

@@ -52,14 +52,25 @@ function roots_root_relative_url($input) {
return $output; 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'))) { if (!is_admin() && !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) {
$tags = array( $tags = array(
'bloginfo_url', 'bloginfo_url',
'theme_root_uri', 'theme_root_uri',
'stylesheet_directory_uri', 'stylesheet_directory_uri',
'template_directory_uri', 'template_directory_uri',
'script_loader_src',
'style_loader_src',
'plugins_url', 'plugins_url',
'the_permalink', 'the_permalink',
'wp_list_pages', 'wp_list_pages',
@@ -77,6 +88,9 @@ if (!is_admin() && !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-regi
); );
add_filters($tags, 'roots_root_relative_url'); add_filters($tags, 'roots_root_relative_url');
add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
} }
// remove root relative URLs on any attachments in the feed // remove root relative URLs on any attachments in the feed
@@ -652,4 +666,4 @@ if (class_exists('RGForms')) {
} }
add_filter('gform_submit_button', 'roots_gform_submit_button', 10, 2); add_filter('gform_submit_button', 'roots_gform_submit_button', 10, 2);
} }