From 6479e66f38250703c0da29be2ffd830bdbc6453f Mon Sep 17 00:00:00 2001 From: Scott Walkinshaw Date: Wed, 10 Aug 2011 20:04:21 -0600 Subject: [PATCH] Fixed #114 + updates to wp_enqueue_script and style --- inc/roots-cleanup.php | 33 +++++++++++++++++++++++++++++---- inc/roots-htaccess.php | 2 ++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/inc/roots-cleanup.php b/inc/roots-cleanup.php index c8c34b3..8c27347 100644 --- a/inc/roots-cleanup.php +++ b/inc/roots-cleanup.php @@ -26,7 +26,7 @@ add_filter('get_search_query', 'roots_search_query'); // thanks to Scott Walkinshaw (scottwalkinshaw.com) function roots_root_relative_url($input) { $output = preg_replace_callback( - '/(https?:\/\/[^\/|"]+)([^"]+)?/', + '!(https?://[^/|"]+)([^"]+)?!', create_function( '$matches', // if full URL is site_url, return a slash for relative root @@ -41,11 +41,26 @@ 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()) { 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'); @@ -125,7 +140,7 @@ function roots_remove_recent_comments_style() { // remove CSS from gallery function roots_gallery_style($css) { - return preg_replace("/!s", '', $css); } function roots_head_cleanup() { @@ -383,7 +398,7 @@ add_filter('comment_id_fields', 'roots_remove_self_closing_tags'); // you want to change this or remove it because it's used as the description in the RSS feed function roots_notice_tagline() { echo '
'; - echo '

' . sprintf(__('Please update your site tagline', 'roots'), admin_url('options-general.php')) . '

'; + echo '

', sprintf(__('Please update your site tagline', 'roots'), admin_url('options-general.php')), '

'; echo '
'; } @@ -408,4 +423,14 @@ function roots_change_mce_options($options) { add_filter('tiny_mce_before_init', 'roots_change_mce_options'); -?> \ No newline at end of file +//clean up the default WordPress style tags +add_filter('style_loader_tag', 'roots_clean_style_tag'); + +function roots_clean_style_tag($input) { + preg_match_all("!!", $input, $matches); + //only display media if it's print + $media = $matches[3][0] === 'print' ? ' media="print"' : ''; + return '' . "\n"; +} + +?> diff --git a/inc/roots-htaccess.php b/inc/roots-htaccess.php index e1a12d5..726d66d 100644 --- a/inc/roots-htaccess.php +++ b/inc/roots-htaccess.php @@ -57,6 +57,8 @@ if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) { add_filter('bloginfo', 'roots_clean_assets'); add_filter('stylesheet_directory_uri', 'roots_clean_assets'); add_filter('template_directory_uri', 'roots_clean_assets'); + add_filter('script_loader_src', 'roots_clean_plugins'); + add_filter('style_loader_src', 'roots_clean_plugins'); } }