From 88eb376958414849bf8ebed9f7da1103fc9fa2a3 Mon Sep 17 00:00:00 2001 From: Nathan Smith Date: Mon, 16 Jan 2012 12:53:35 -0700 Subject: [PATCH] refs #120 - possible fix for 500 server error --- inc/h5bp-htaccess | 7 +++---- inc/roots-htaccess.php | 39 ++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/inc/h5bp-htaccess b/inc/h5bp-htaccess index c331e9d..26972eb 100644 --- a/inc/h5bp-htaccess +++ b/inc/h5bp-htaccess @@ -1,5 +1,4 @@ - -# BEGIN HTML5 Boilerplate .htaccess +## BEGIN HTML5 Boilerplate ### ### This contains the HTML5 Boilerplate .htaccess that can be found at: @@ -18,7 +17,7 @@ ### ### Anytime you update this file the .htaccess file in the root of your ### WordPress install is automatically updated with the changes whenever -### the admin is refreshed (see roots-htaccess.php) +### the permalinks are flushed or set ### @@ -552,4 +551,4 @@ AddCharset utf-8 .css .js .xml .json .rss .atom php_value session.cookie_httponly true -# END HTML5 Boilerplate +# END HTML5 Boilerplate \ No newline at end of file diff --git a/inc/roots-htaccess.php b/inc/roots-htaccess.php index af03e43..3bc08e1 100644 --- a/inc/roots-htaccess.php +++ b/inc/roots-htaccess.php @@ -21,25 +21,19 @@ if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) { // rewrite /wp-content/themes/roots/img/ to /js/ // rewrite /wp-content/plugins/ to /plugins/ - function roots_flush_rewrites() { - global $wp_rewrite; - $wp_rewrite->flush_rules(); - } - function roots_add_rewrites($content) { - $theme_name = next(explode('/themes/', get_stylesheet_directory())); global $wp_rewrite; + $theme_name = next(explode('/themes/', get_stylesheet_directory())); $roots_new_non_wp_rules = array( 'css/(.*)' => 'wp-content/themes/'. $theme_name . '/css/$1', 'js/(.*)' => 'wp-content/themes/'. $theme_name . '/js/$1', 'img/(.*)' => 'wp-content/themes/'. $theme_name . '/img/$1', 'plugins/(.*)' => 'wp-content/plugins/$1' ); - $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules; + $wp_rewrite->non_wp_rules = $roots_new_non_wp_rules; + return $content; } - add_action('admin_init', 'roots_flush_rewrites'); - function roots_clean_assets($content) { $theme_name = next(explode('/themes/', $content)); $current_path = '/wp-content/themes/' . $theme_name; @@ -58,6 +52,7 @@ if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) { // only use clean urls if the theme isn't a child or an MU (Network) install if (!is_multisite() && !is_child_theme()) { add_action('generate_rewrite_rules', 'roots_add_rewrites'); + add_action('generate_rewrite_rules', 'roots_add_h5bp_htaccess'); if (!is_admin()) { add_filter('plugins_url', 'roots_clean_plugins'); add_filter('bloginfo', 'roots_clean_assets'); @@ -69,19 +64,25 @@ if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) { } // add the contents of h5bp-htaccess into the .htaccess file - function roots_add_h5bp_htaccess($rules) { - global $wp_filesystem; + function roots_add_h5bp_htaccess($content) { + global $wp_rewrite; - if (!defined('FS_METHOD')) define('FS_METHOD', 'direct'); - if (is_null($wp_filesystem)) WP_Filesystem(array(), ABSPATH); - - $filename = __DIR__ . '/h5bp-htaccess'; - - return $rules . $wp_filesystem->get_contents($filename); + $home_path = get_home_path(); + $htaccess_file = $home_path . '.htaccess'; + + if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) { + if (got_mod_rewrite()) { + $h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate'); + if ($h5bp_rules === array()) { + $filename = __DIR__ . '/h5bp-htaccess'; + return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate')); + } + } + } + + return $content; } - add_filter('mod_rewrite_rules', 'roots_add_h5bp_htaccess'); - } ?> \ No newline at end of file