Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* current wp file : functions.php
- purpose : hide all wp references in source code
- for a Buddypress theme or child theme
- You will have to edit your .htaccess file too
- (code at the bottom of this page...)
- contact : mecanographik.fr
- */
- // Hide The Fact That You’re Using WordPress ! //
- //inspired by source :
- // http://benword.com/2011/how-to-hide-that-youre-using-wordpress/
- /* ############################################### */
- // Start by cleaning up the output of wp_head
- remove_action('wp_head', 'feed_links', 2);
- remove_action('wp_head', 'feed_links_extra', 3);
- remove_action('wp_head', 'rsd_link');
- remove_action('wp_head', 'wlwmanifest_link');
- remove_action('wp_head', 'index_rel_link');
- remove_action('wp_head', 'parent_post_rel_link', 10, 0);
- remove_action('wp_head', 'start_post_rel_link', 10, 0);
- remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
- remove_action('wp_head', 'wp_generator');
- remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
- remove_action('wp_head', 'noindex', 1);
- // remove WordPress version from RSS feeds
- function roots_no_generator() { return ''; }
- add_filter('the_generator', 'roots_no_generator');
- // Remove unnecessary scripts
- if (!is_admin()) {
- wp_deregister_script('l10n');
- }
- // Remove unnecessary CSS
- // remove CSS from recent comments widget
- function roots_remove_recent_comments_style() {
- global $wp_widget_factory;
- if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
- remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
- }
- }
- add_action('wp_head', 'roots_remove_recent_comments_style', 1);
- // Hide /wp-content/
- // Hide plugins and Buddypress references too
- // Rewrite static theme assets and plugins directory
- // rewrite /wp-content/themes/theme-name/css/ to /css/
- // rewrite /wp-content/themes/theme-name/js/ to /js/
- // rewrite /wp-content/themes/theme-name/img/ to /img/
- // rewrite /wp-content/plugins/ to /plugins/
- /* rewrite '/wp-content/plugins/buddypress/bp-themes/bp-default/_inc/' TO '/_inc/' */
- function roots_flush_rewrites() {
- global $wp_rewrite;
- $wp_rewrite->flush_rules();
- }
- function roots_add_rewrites($content) {
- $theme_name = next(explode('/themes/', get_stylesheet_directory()));
- global $wp_rewrite;
- $roots_new_non_wp_rules = array(
- 'css/(.*)' => 'wp-content/themes/'. $theme_name . '/$1',
- //'js/(.*)' => 'wp-content/themes/'. $theme_name . '/js/$1',
- //'img/(.*)' => 'wp-content/themes/'. $theme_name . '/img/$1',
- 'inc/(.*)' => 'wp-includes/$1',
- 'pl/(.*)' => 'wp-content/plugins/$1',
- 'ml/(.*)' => 'wp-content/plugins/buddypress/bp-themes/bp-default/_inc/$1',
- 'core/(.*)' => 'wp-content/plugins/buddypress/bp-core/$1'
- );
- $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules;
- }
- add_action('admin_init', 'roots_flush_rewrites');
- function roots_clean_assets($content) {
- $theme_name = next(explode('/themes/', $content));
- $current_path = '/wp-content/themes/' . $theme_name;
- $new_path = '/css';
- $content = str_replace($current_path, $new_path, $content);
- return $content;
- }
- function roots_clean_plugins_bp($content) {
- $current_path = '/wp-content/plugins/buddypress/bp-themes/bp-default/_inc';
- $new_path = '/ml';
- $content = str_replace($current_path, $new_path, $content);
- return $content;
- }
- function roots_clean_plugins_bp_core($content) {
- $current_path = '/wp-content/plugins/buddypress/bp-core';
- $new_path = '/core';
- $content = str_replace($current_path, $new_path, $content);
- return $content;
- }
- function roots_clean_plugins($content) {
- $current_path = '/wp-content/plugins';
- $new_path = '/pl'; // or whatever you want for a new folder name
- $content = str_replace($current_path, $new_path, $content);
- return $content;
- }
- function roots_clean_includes($content) {
- $current_path = '/wp-includes';
- $new_path = '/inc';
- $content = str_replace($current_path, $new_path, $content);
- return $content;
- }
- add_action('generate_rewrite_rules', 'roots_add_rewrites');
- if (!is_admin()) {
- add_filter('plugins_url', 'roots_clean_plugins_bp');
- add_filter('plugins_url', 'roots_clean_plugins');
- add_filter('bloginfo', 'roots_clean_assets');
- add_filter('stylesheet_directory_uri', 'roots_clean_assets');
- add_filter('template_directory_uri', 'roots_clean_assets');
- add_filter('script_loader_src', 'roots_clean_plugins_bp');
- add_filter('script_loader_src', 'roots_clean_plugins_bp_core');
- add_filter('script_loader_src', 'roots_clean_plugins');
- add_filter('script_loader_src', 'roots_clean_includes');
- add_filter('style_loader_src', 'roots_clean_includes');
- add_filter('style_loader_src', 'roots_clean_plugins_bp');
- add_filter('style_loader_src', 'roots_clean_plugins');
- }
- // Change location of WordPress uploads
- update_option('uploads_use_yearmonth_folders', 0);
- update_option('upload_path', 'ml-medias');
- // Root relative URLs in WordPress
- function roots_root_relative_url($input) {
- $output = preg_replace_callback(
- '!(https?://[^/|"]+)([^"]+)?!',
- create_function(
- '$matches',
- // if full URL is site_url, return a slash for relative root
- 'if (isset($matches[0]) && $matches[0] === site_url()) { return "/";' .
- // if domain is equal to site_url, then make URL relative
- '} elseif (isset($matches[0]) && strpos($matches[0], site_url()) !== false) { return $matches[2];' .
- // if domain is not equal to site_url, do not make external link relative
- '} else { return $matches[0]; };'
- ),
- $input
- );
- return $output;
- }
- // workaround to remove the duplicate subfolder in the src of JS/CSS tags
- // example: /subfolder/subfolder/css/style.css
- function roots_fix_duplicate_subfolder_urls($input) {
- $output = roots_root_relative_url($input);
- preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);
- if (isset($matches[1]) && isset($matches[2])) {
- if ($matches[1][0] === $matches[2][0]) {
- $output = substr($output, strlen($matches[1][0]) + 1);
- }
- }
- return $output;
- }
- if (!is_admin() && !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) {
- add_filter('bloginfo_url', 'roots_root_relative_url');
- add_filter('theme_root_uri', 'roots_root_relative_url');
- add_filter('stylesheet_directory_uri', 'roots_root_relative_url');
- add_filter('template_directory_uri', 'roots_root_relative_url');
- add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
- add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
- add_filter('plugins_url', 'roots_root_relative_url');
- add_filter('the_permalink', 'roots_root_relative_url');
- add_filter('wp_list_pages', 'roots_root_relative_url');
- add_filter('wp_list_categories', 'roots_root_relative_url');
- add_filter('wp_nav_menu', 'roots_root_relative_url');
- add_filter('the_content_more_link', 'roots_root_relative_url');
- add_filter('the_tags', 'roots_root_relative_url');
- add_filter('get_pagenum_link', 'roots_root_relative_url');
- add_filter('get_comment_link', 'roots_root_relative_url');
- add_filter('month_link', 'roots_root_relative_url');
- add_filter('day_link', 'roots_root_relative_url');
- add_filter('year_link', 'roots_root_relative_url');
- add_filter('tag_link', 'roots_root_relative_url');
- add_filter('the_author_posts_link', 'roots_root_relative_url');
- }
- /* ---------------------------------------------------------------------------------------------
- and below the code to add to your .htaccess file :
- Be carefull, replace "nameofyourchildtheme" with the name of your child theme placed in your 'wp-content/themes' folder...
- ------------------------------------------------------------------------------------------------*/
- RewriteRule ^css/(.*) /wp-content/themes/nameofyourchildtheme/$1 [QSA,L]
- RewriteRule ^js/(.*) /wp-content/themes/nameofyourchildtheme/js/$1 [QSA,L]
- RewriteRule ^img/(.*) /wp-content/themes/nameofyourchildtheme/img/$1 [QSA,L]
- RewriteRule ^pl/(.*) /wp-content/plugins/$1 [QSA,L]
- RewriteRule ^ml/(.*) /wp-content/plugins/buddypress/bp-themes/bp-default/_inc/$1 [QSA,L]
- RewriteRule ^core/(.*) /wp-content/plugins/buddypress/bp-core/$1 [QSA,L]
- RewriteRule ^inc/(.*) /wp-includes/$1 [QSA,L]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement