From 69a42d05df7ad9bec46e4c8d2c87e9a981d44634 Mon Sep 17 00:00:00 2001 From: Scott Walkinshaw Date: Tue, 10 Apr 2012 21:05:52 -0400 Subject: [PATCH] Restore duplicate subfolder removal --- inc/roots-cleanup.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/inc/roots-cleanup.php b/inc/roots-cleanup.php index 0389877..ccd19e0 100644 --- a/inc/roots-cleanup.php +++ b/inc/roots-cleanup.php @@ -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', @@ -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_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 @@ -652,4 +666,4 @@ if (class_exists('RGForms')) { } add_filter('gform_submit_button', 'roots_gform_submit_button', 10, 2); -} \ No newline at end of file +}