not apache? no need to continue. found this check from the w3 total

cache plugin.
This commit is contained in:
Ben Word
2011-07-31 02:37:22 -06:00
parent 37b8d099e7
commit 5d298fbead

View File

@@ -1,27 +1,28 @@
<?php <?php
function roots_htaccess_writable() { if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
function roots_htaccess_writable() {
if (!is_writable(get_home_path() . '.htaccess')) { if (!is_writable(get_home_path() . '.htaccess')) {
add_action('admin_notices', create_function('', "echo '<div class=\"error\"><p>" . sprintf(__('Please make sure your <a href="%s">.htaccess</a> file is writeable ', 'roots'), admin_url('options-permalink.php')) . "</p></div>';")); add_action('admin_notices', create_function('', "echo '<div class=\"error\"><p>" . sprintf(__('Please make sure your <a href="%s">.htaccess</a> file is writeable ', 'roots'), admin_url('options-permalink.php')) . "</p></div>';"));
}; };
} }
add_action('admin_init', 'roots_htaccess_writable'); add_action('admin_init', 'roots_htaccess_writable');
$theme_name = next(explode('/themes/', get_stylesheet_directory())); $theme_name = next(explode('/themes/', get_stylesheet_directory()));
// Rewrites DO NOT happen for child themes // Rewrites DO NOT happen for child themes
// rewrite /wp-content/themes/roots/css/ to /css/ // rewrite /wp-content/themes/roots/css/ to /css/
// rewrite /wp-content/themes/roots/js/ to /js/ // rewrite /wp-content/themes/roots/js/ to /js/
// rewrite /wp-content/themes/roots/img/ to /js/ // rewrite /wp-content/themes/roots/img/ to /js/
// rewrite /wp-content/plugins/ to /plugins/ // rewrite /wp-content/plugins/ to /plugins/
function roots_flush_rewrites() { function roots_flush_rewrites() {
global $wp_rewrite; global $wp_rewrite;
$wp_rewrite->flush_rules(); $wp_rewrite->flush_rules();
} }
function roots_add_rewrites($content) { function roots_add_rewrites($content) {
$theme_name = next(explode('/themes/', get_stylesheet_directory())); $theme_name = next(explode('/themes/', get_stylesheet_directory()));
global $wp_rewrite; global $wp_rewrite;
$roots_new_non_wp_rules = array( $roots_new_non_wp_rules = array(
@@ -31,27 +32,27 @@ function roots_add_rewrites($content) {
'plugins/(.*)' => 'wp-content/plugins/$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;
} }
add_action('admin_init', 'roots_flush_rewrites'); add_action('admin_init', 'roots_flush_rewrites');
function roots_clean_assets($content) { function roots_clean_assets($content) {
$theme_name = next(explode('/themes/', $content)); $theme_name = next(explode('/themes/', $content));
$current_path = '/wp-content/themes/' . $theme_name; $current_path = '/wp-content/themes/' . $theme_name;
$new_path = ''; $new_path = '';
$content = str_replace($current_path, $new_path, $content); $content = str_replace($current_path, $new_path, $content);
return $content; return $content;
} }
function roots_clean_plugins($content) { function roots_clean_plugins($content) {
$current_path = '/wp-content/plugins'; $current_path = '/wp-content/plugins';
$new_path = '/plugins'; $new_path = '/plugins';
$content = str_replace($current_path, $new_path, $content); $content = str_replace($current_path, $new_path, $content);
return $content; return $content;
} }
// only use clean urls if the theme isn't a child or an MU (Network) install // only use clean urls if the theme isn't a child or an MU (Network) install
if ((!defined('WP_ALLOW_MULTISITE') || (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE !== true)) && !is_child_theme()) { if ((!defined('WP_ALLOW_MULTISITE') || (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE !== true)) && !is_child_theme()) {
add_action('generate_rewrite_rules', 'roots_add_rewrites'); add_action('generate_rewrite_rules', 'roots_add_rewrites');
if (!is_admin()) { if (!is_admin()) {
add_filter('plugins_url', 'roots_clean_plugins'); add_filter('plugins_url', 'roots_clean_plugins');
@@ -59,9 +60,9 @@ if ((!defined('WP_ALLOW_MULTISITE') || (defined('WP_ALLOW_MULTISITE') && WP_ALLO
add_filter('stylesheet_directory_uri', 'roots_clean_assets'); add_filter('stylesheet_directory_uri', 'roots_clean_assets');
add_filter('template_directory_uri', 'roots_clean_assets'); add_filter('template_directory_uri', 'roots_clean_assets');
} }
} }
function roots_add_h5bp_htaccess($rules) { function roots_add_h5bp_htaccess($rules) {
global $wp_filesystem; global $wp_filesystem;
if (!defined('FS_METHOD')) define('FS_METHOD', 'direct'); if (!defined('FS_METHOD')) define('FS_METHOD', 'direct');
@@ -76,8 +77,9 @@ function roots_add_h5bp_htaccess($rules) {
$rules .= $wp_filesystem->get_contents($filename); $rules .= $wp_filesystem->get_contents($filename);
return $rules; return $rules;
}
add_action('mod_rewrite_rules', 'roots_add_h5bp_htaccess');
} }
add_action('mod_rewrite_rules', 'roots_add_h5bp_htaccess');
?> ?>