Advertisement
Guest User

Copy of Mecanographik's code without line numbers

a guest
Feb 8th, 2013
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.26 KB | None | 0 0
  1. /* current wp file : functions.php
  2. purpose : hide all wp references in source code
  3. for a Buddypress theme or child theme
  4. You will have to edit your .htaccess file too
  5. (code at the bottom of this page...)
  6. contact : mecanographik.fr
  7. */
  8. // Hide The Fact That You’re Using WordPress ! //
  9. //inspired by source :
  10. // http://benword.com/2011/how-to-hide-that-youre-using-wordpress/
  11. /* ############################################### */
  12. // Start by cleaning up the output of wp_head
  13. remove_action('wp_head', 'feed_links', 2);
  14. remove_action('wp_head', 'feed_links_extra', 3);
  15. remove_action('wp_head', 'rsd_link');
  16. remove_action('wp_head', 'wlwmanifest_link');
  17. remove_action('wp_head', 'index_rel_link');
  18. remove_action('wp_head', 'parent_post_rel_link', 10, 0);
  19. remove_action('wp_head', 'start_post_rel_link', 10, 0);
  20. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
  21. remove_action('wp_head', 'wp_generator');
  22. remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
  23. remove_action('wp_head', 'noindex', 1);
  24. // remove WordPress version from RSS feeds
  25. function roots_no_generator() { return ''; }
  26. add_filter('the_generator', 'roots_no_generator');
  27. // Remove unnecessary scripts
  28. if (!is_admin()) {
  29. wp_deregister_script('l10n');
  30. }
  31. // Remove unnecessary CSS
  32. // remove CSS from recent comments widget
  33. function roots_remove_recent_comments_style() {
  34. global $wp_widget_factory;
  35. if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
  36. remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
  37.  
  38. }
  39.  
  40. }
  41.  
  42. add_action('wp_head', 'roots_remove_recent_comments_style', 1);
  43. // Hide /wp-content/
  44. // Hide plugins and Buddypress references too
  45. // Rewrite static theme assets and plugins directory
  46. // rewrite /wp-content/themes/theme-name/css/ to /css/
  47. // rewrite /wp-content/themes/theme-name/js/ to /js/
  48. // rewrite /wp-content/themes/theme-name/img/ to /img/
  49. // rewrite /wp-content/plugins/ to /plugins/
  50. /* rewrite '/wp-content/plugins/buddypress/bp-themes/bp-default/_inc/' TO '/_inc/' */
  51. function roots_flush_rewrites() {
  52. global $wp_rewrite;
  53. $wp_rewrite->flush_rules();
  54.  
  55. }
  56.  
  57. function roots_add_rewrites($content) {
  58. $theme_name = next(explode('/themes/', get_stylesheet_directory()));
  59. global $wp_rewrite;
  60.  
  61. $roots_new_non_wp_rules = array(
  62. 'css/(.*)' => 'wp-content/themes/'. $theme_name . '/$1',
  63. //'js/(.*)' => 'wp-content/themes/'. $theme_name . '/js/$1',
  64. //'img/(.*)' => 'wp-content/themes/'. $theme_name . '/img/$1',
  65. 'inc/(.*)' => 'wp-includes/$1',
  66. 'pl/(.*)' => 'wp-content/plugins/$1',
  67. 'ml/(.*)' => 'wp-content/plugins/buddypress/bp-themes/bp-default/_inc/$1',
  68. 'core/(.*)' => 'wp-content/plugins/buddypress/bp-core/$1'
  69. );
  70. $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules;
  71. }
  72.  
  73. add_action('admin_init', 'roots_flush_rewrites');
  74. function roots_clean_assets($content) {
  75. $theme_name = next(explode('/themes/', $content));
  76. $current_path = '/wp-content/themes/' . $theme_name;
  77. $new_path = '/css';
  78. $content = str_replace($current_path, $new_path, $content);
  79. return $content;
  80. }
  81. function roots_clean_plugins_bp($content) {
  82. $current_path = '/wp-content/plugins/buddypress/bp-themes/bp-default/_inc';
  83. $new_path = '/ml';
  84. $content = str_replace($current_path, $new_path, $content);
  85. return $content;
  86. }
  87. function roots_clean_plugins_bp_core($content) {
  88. $current_path = '/wp-content/plugins/buddypress/bp-core';
  89. $new_path = '/core';
  90. $content = str_replace($current_path, $new_path, $content);
  91. return $content;
  92. }
  93.  
  94. function roots_clean_plugins($content) {
  95. $current_path = '/wp-content/plugins';
  96. $new_path = '/pl'; // or whatever you want for a new folder name
  97. $content = str_replace($current_path, $new_path, $content);
  98.  
  99. return $content;
  100.  
  101. }
  102.  
  103. function roots_clean_includes($content) {
  104. $current_path = '/wp-includes';
  105. $new_path = '/inc';
  106. $content = str_replace($current_path, $new_path, $content);
  107. return $content;
  108. }
  109. add_action('generate_rewrite_rules', 'roots_add_rewrites');
  110.  
  111. if (!is_admin()) {
  112. add_filter('plugins_url', 'roots_clean_plugins_bp');
  113. add_filter('plugins_url', 'roots_clean_plugins');
  114. add_filter('bloginfo', 'roots_clean_assets');
  115. add_filter('stylesheet_directory_uri', 'roots_clean_assets');
  116. add_filter('template_directory_uri', 'roots_clean_assets');
  117. add_filter('script_loader_src', 'roots_clean_plugins_bp');
  118. add_filter('script_loader_src', 'roots_clean_plugins_bp_core');
  119. add_filter('script_loader_src', 'roots_clean_plugins');
  120. add_filter('script_loader_src', 'roots_clean_includes');
  121. add_filter('style_loader_src', 'roots_clean_includes');
  122. add_filter('style_loader_src', 'roots_clean_plugins_bp');
  123. add_filter('style_loader_src', 'roots_clean_plugins');
  124. }
  125. // Change location of WordPress uploads
  126. update_option('uploads_use_yearmonth_folders', 0);
  127. update_option('upload_path', 'ml-medias');
  128. // Root relative URLs in WordPress
  129. function roots_root_relative_url($input) {
  130. $output = preg_replace_callback(
  131. '!(https?://[^/|"]+)([^"]+)?!',
  132. create_function(
  133. '$matches',
  134. // if full URL is site_url, return a slash for relative root
  135. 'if (isset($matches[0]) && $matches[0] === site_url()) { return "/";' .
  136. // if domain is equal to site_url, then make URL relative
  137. '} elseif (isset($matches[0]) && strpos($matches[0], site_url()) !== false) { return $matches[2];' .
  138.  
  139. // if domain is not equal to site_url, do not make external link relative
  140.  
  141. '} else { return $matches[0]; };'
  142. ),
  143. $input
  144. );
  145. return $output;
  146.  
  147. }
  148.  
  149. // workaround to remove the duplicate subfolder in the src of JS/CSS tags
  150. // example: /subfolder/subfolder/css/style.css
  151. function roots_fix_duplicate_subfolder_urls($input) {
  152. $output = roots_root_relative_url($input);
  153. preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);
  154. if (isset($matches[1]) && isset($matches[2])) {
  155. if ($matches[1][0] === $matches[2][0]) {
  156. $output = substr($output, strlen($matches[1][0]) + 1);
  157. }
  158.  
  159. }
  160.  
  161. return $output;
  162. }
  163.  
  164. if (!is_admin() && !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) {
  165. add_filter('bloginfo_url', 'roots_root_relative_url');
  166. add_filter('theme_root_uri', 'roots_root_relative_url');
  167. add_filter('stylesheet_directory_uri', 'roots_root_relative_url');
  168. add_filter('template_directory_uri', 'roots_root_relative_url');
  169. add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
  170. add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
  171. add_filter('plugins_url', 'roots_root_relative_url');
  172. add_filter('the_permalink', 'roots_root_relative_url');
  173. add_filter('wp_list_pages', 'roots_root_relative_url');
  174. add_filter('wp_list_categories', 'roots_root_relative_url');
  175. add_filter('wp_nav_menu', 'roots_root_relative_url');
  176. add_filter('the_content_more_link', 'roots_root_relative_url');
  177. add_filter('the_tags', 'roots_root_relative_url');
  178. add_filter('get_pagenum_link', 'roots_root_relative_url');
  179. add_filter('get_comment_link', 'roots_root_relative_url');
  180. add_filter('month_link', 'roots_root_relative_url');
  181. add_filter('day_link', 'roots_root_relative_url');
  182. add_filter('year_link', 'roots_root_relative_url');
  183. add_filter('tag_link', 'roots_root_relative_url');
  184. add_filter('the_author_posts_link', 'roots_root_relative_url');
  185. }
  186. /* ---------------------------------------------------------------------------------------------
  187. and below the code to add to your .htaccess file :
  188. Be carefull, replace "nameofyourchildtheme" with the name of your child theme placed in your 'wp-content/themes' folder...
  189. ------------------------------------------------------------------------------------------------*/
  190. RewriteRule ^css/(.*) /wp-content/themes/nameofyourchildtheme/$1 [QSA,L]
  191. RewriteRule ^js/(.*) /wp-content/themes/nameofyourchildtheme/js/$1 [QSA,L]
  192. RewriteRule ^img/(.*) /wp-content/themes/nameofyourchildtheme/img/$1 [QSA,L]
  193. RewriteRule ^pl/(.*) /wp-content/plugins/$1 [QSA,L]
  194. RewriteRule ^ml/(.*) /wp-content/plugins/buddypress/bp-themes/bp-default/_inc/$1 [QSA,L]
  195. RewriteRule ^core/(.*) /wp-content/plugins/buddypress/bp-core/$1 [QSA,L]
  196. RewriteRule ^inc/(.*) /wp-includes/$1 [QSA,L]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement