Fix #250 - update htaccess functions to latest from @alkymst

This commit is contained in:
Ben Word
2012-02-13 08:25:25 -07:00
parent 49300042c8
commit 551fc9ca50

View File

@@ -35,25 +35,24 @@ if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
}
function roots_clean_assets($content) {
$theme_name = next(explode('/themes/', $content));
$current_path = '/wp-content/themes/' . $theme_name;
$new_path = '';
$content = str_replace($current_path, $new_path, $content);
return $content;
$theme_name = next(explode('/themes/', $content));
$current_path = '/wp-content/themes/' . $theme_name;
$new_path = '';
$content = str_replace($current_path, $new_path, $content);
return $content;
}
function roots_clean_plugins($content) {
$current_path = '/wp-content/plugins';
$new_path = '/plugins';
$content = str_replace($current_path, $new_path, $content);
return $content;
$current_path = '/wp-content/plugins';
$new_path = '/plugins';
$content = str_replace($current_path, $new_path, $content);
return $content;
}
// 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');
add_action('activate_plugin', 'roots_add_h5bp_htaccess');
if (!is_admin()) {
add_filter('plugins_url', 'roots_clean_plugins');
add_filter('bloginfo', 'roots_clean_assets');
@@ -67,20 +66,16 @@ if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
// add the contents of h5bp-htaccess into the .htaccess file
function roots_add_h5bp_htaccess($content) {
global $wp_rewrite;
if (!function_exists('get_home_path')) {
return;
}
$home_path = get_home_path();
$home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH;
$htaccess_file = $home_path . '.htaccess';
$mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false;
if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
if (got_mod_rewrite()) {
if ($mod_rewrite_enabled) {
$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 insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate'));
}
}
}