Skip to content

Commit

Permalink
Restore duplicate subfolder removal
Browse files Browse the repository at this point in the history
  • Loading branch information
swalkinshaw committed Apr 11, 2012
1 parent 060ab1b commit 69a42d0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions inc/roots-cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@ 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'))) {
$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',
Expand All @@ -77,6 +88,9 @@ function roots_root_relative_url($input) {
);

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
Expand Down Expand Up @@ -652,4 +666,4 @@ function roots_gform_submit_button($button, $form) {
}
add_filter('gform_submit_button', 'roots_gform_submit_button', 10, 2);

}
}

0 comments on commit 69a42d0

Please sign in to comment.