brasofilo

Remove WP-CONTENT : functions.php

Oct 12th, 2011
270
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.  
  20.     function roots_flush_rewrites() {
  21.         global $wp_rewrite;
  22.         $wp_rewrite->flush_rules();
  23.     }
  24.  
  25.     function roots_add_rewrites($content) {
  26.         $theme_name = next(explode('/themes/', get_stylesheet_directory()));
  27.         global $wp_rewrite;
  28.         $roots_new_non_wp_rules = array(
  29.             'css/(.*)'      => 'wp-content/themes/'. $theme_name . '/css/$1',
  30.             'js/(.*)'       => 'wp-content/themes/'. $theme_name . '/js/$1',
  31.             'framework/(.*)'       => 'wp-content/themes/'. $theme_name . '/framework/$1',
  32.             'images/(.*)'      => 'wp-content/themes/'. $theme_name . '/images/$1',
  33.             'uploads/(.*)'      => 'wp-content/uploads/$1',
  34.             'plugins/(.*)'  => 'wp-content/plugins/$1'
  35.         );
  36.         $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules;
  37.     }
  38.  
  39.     add_action('admin_init', 'roots_flush_rewrites');
  40.  
  41.     function roots_clean_assets($content) {
  42.         $theme_name = next(explode('/themes/', $content));
  43.         $current_path = '/wp-content/themes/' . $theme_name;
  44.         $new_path = '';
  45.         $content = str_replace($current_path, $new_path, $content);
  46.         return $content;
  47.     }
  48.  
  49.     function roots_clean_plugins($content) {
  50.         $current_path = '/wp-content/plugins';
  51.         $new_path = '/plugins';
  52.         $content = str_replace($current_path, $new_path, $content);
  53.         return $content;
  54.     }
  55.  
  56.     // only use clean urls if the theme isn't a child or an MU (Network) install
  57.     if (!is_multisite() && !is_child_theme()) {
  58.         add_action('generate_rewrite_rules', 'roots_add_rewrites');
  59.         if (!is_admin()) {
  60.             add_filter('plugins_url', 'roots_clean_plugins');
  61.             add_filter('bloginfo', 'roots_clean_assets');
  62.             add_filter('stylesheet_directory_uri', 'roots_clean_assets');
  63.             add_filter('template_directory_uri', 'roots_clean_assets');
  64.       add_filter('script_loader_src', 'roots_clean_plugins');
  65.       add_filter('style_loader_src', 'roots_clean_plugins');
  66.         }
  67.     }
  68.  
  69.     function roots_add_h5bp_htaccess($rules) {
  70.         global $wp_filesystem;
  71.  
  72.         if (!defined('FS_METHOD')) define('FS_METHOD', 'direct');
  73.         if (is_null($wp_filesystem)) WP_Filesystem(array(), ABSPATH);
  74.    
  75.         if (!defined('WP_CONTENT_DIR'))
  76.         define('WP_CONTENT_DIR', ABSPATH . 'wp-content');  
  77.  
  78.         $theme_name = next(explode('/themes/', get_template_directory()));
  79.         $filename = WP_CONTENT_DIR . '/themes/' . $theme_name . '/inc/h5bp-htaccess';
  80.  
  81.         $rules .= $wp_filesystem->get_contents($filename);
  82.    
  83.         return $rules;
  84.     }
  85.  
  86.     add_action('mod_rewrite_rules', 'roots_add_h5bp_htaccess');
  87. }
  88.  
  89. if (!is_admin()){
  90.   wp_deregister_script('l10n');
  91. }
RAW Paste Data