brasofilo

WPSE 25418

Jun 7th, 2012
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // REMOVE WP-CONTENT
  2. // Rewrites DO NOT happen for child themes
  3. /*
  4.  in case your wordpress is in a folder,
  5.  and you change the site_url to the root of the domain,
  6.  add the folder name in lines 29 to 34,
  7.  i.e.: => 'YOUR-WP-FOLDER/wp-content/themes/'
  8. */
  9.  
  10. if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
  11.     function roots_htaccess_writable() {
  12.         if (!is_writable(get_home_path() . '.htaccess')) {
  13.             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>';"));
  14.         };
  15.     }
  16.  
  17.     add_action('admin_init', 'roots_htaccess_writable');
  18.  
  19.     // Rewrites DO NOT happen for child themes
  20.     // rewrite /wp-content/themes/roots/css/ to /css/
  21.     // rewrite /wp-content/themes/roots/js/  to /js/
  22.     // rewrite /wp-content/themes/roots/img/ to /js/
  23.     // rewrite /wp-content/plugins/ to /plugins/
  24.  
  25.     function roots_flush_rewrites() {
  26.         global $wp_rewrite;
  27.         $wp_rewrite->flush_rules();
  28.     }
  29.  
  30.     function roots_add_rewrites($content) {
  31.         $theme_name = next(explode('/themes/', get_stylesheet_directory()));
  32.         global $wp_rewrite;
  33.         $roots_new_non_wp_rules = array(
  34.             'css/(.*)'      => 'wp-content/themes/'. $theme_name . '/css/$1',
  35.             'js/(.*)'       => 'wp-content/themes/'. $theme_name . '/js/$1',
  36.             'img/(.*)'      => 'wp-content/themes/'. $theme_name . '/img/$1',
  37.             'plugins/(.*)'  => 'wp-content/plugins/$1'
  38.         );
  39.         $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules;
  40.     }
  41.  
  42.     add_action('admin_init', 'roots_flush_rewrites');
  43.  
  44.     function roots_clean_assets($content) {
  45.         $theme_name = next(explode('/themes/', $content));
  46.         $current_path = '/wp-content/themes/' . $theme_name;
  47.         $new_path = '';
  48.         $content = str_replace($current_path, $new_path, $content);
  49.         return $content;
  50.     }
  51.  
  52.     function roots_clean_plugins($content) {
  53.         $current_path = '/wp-content/plugins';
  54.         $new_path = '/plugins';
  55.         $content = str_replace($current_path, $new_path, $content);
  56.         return $content;
  57.     }
  58.  
  59.     // only use clean urls if the theme isn't a child or an MU (Network) install
  60.     if (!is_multisite() && !is_child_theme()) {
  61.         add_action('generate_rewrite_rules', 'roots_add_rewrites');
  62.         if (!is_admin()) {
  63.             add_filter('plugins_url', 'roots_clean_plugins');
  64.             add_filter('bloginfo', 'roots_clean_assets');
  65.             add_filter('stylesheet_directory_uri', 'roots_clean_assets');
  66.             add_filter('template_directory_uri', 'roots_clean_assets');
  67.         }
  68.     }
  69.  
  70.     function roots_add_h5bp_htaccess($rules) {
  71.         global $wp_filesystem;
  72.  
  73.         if (!defined('FS_METHOD')) define('FS_METHOD', 'direct');
  74.         if (is_null($wp_filesystem)) WP_Filesystem(array(), ABSPATH);
  75.  
  76.         if (!defined('WP_CONTENT_DIR'))
  77.             define('WP_CONTENT_DIR', ABSPATH . 'wp-content');  
  78.  
  79.         $theme_name = next(explode('/themes/', get_template_directory()));
  80.         $filename = WP_CONTENT_DIR . '/themes/' . $theme_name . '/inc/h5bp-htaccess';
  81.  
  82.         $rules .= $wp_filesystem->get_contents($filename);
  83.  
  84.         return $rules;
  85.     }
  86.  
  87.     add_action('mod_rewrite_rules', 'roots_add_h5bp_htaccess');
  88. }
RAW Paste Data