Last active
May 17, 2017 23:10
-
-
Save dimobelov/ce334c934dee4f194514236897658f6b to your computer and use it in GitHub Desktop.
Функции за почистване на Wordpress от ненужна информация
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove meta name=generator | |
*/ | |
public function remove_wp_version() { | |
remove_action( 'wp_head', 'wp_generator' ); | |
add_filter( 'revslider_meta_generator', array( $this, 'remove_revslider_metadata' ) ); | |
$this->remove_visual_composer_metadata(); | |
} | |
/** | |
* Remove Visual Composer Generator | |
*/ | |
public function remove_visual_composer_metadata() { | |
global $vc_manager; | |
if ( $vc_manager ) { | |
remove_action( 'wp_head', array( $vc_manager->vc(), 'addMetaData' ) ); | |
} | |
} | |
/** | |
* Remove Slider Revolution Generator | |
*/ | |
public function remove_revslider_metadata() { | |
return ''; | |
} | |
/** | |
* Remove link rel=wlwmanifest | |
*/ | |
public function remove_wlwmanifest() { | |
remove_action( 'wp_head', 'wlwmanifest_link' ); | |
} | |
/** | |
* Remove link rel=EditURI | |
*/ | |
public function remove_rsd() { | |
remove_action( 'wp_head', 'rsd_link' ); | |
} | |
/** | |
* Remove link rel=shortlink | |
*/ | |
public function remove_shortlink() { | |
remove_action( 'wp_head', 'wp_shortlink_wp_head' ); | |
} | |
/** | |
* Remove link rel=prev,next | |
*/ | |
public function remove_prev_next() { | |
remove_action( 'wp_head', 'start_post_rel_link', 10 ); | |
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10 ); | |
} | |
/** | |
* Remove styles for .recentcomments | |
*/ | |
public function remove_recentcomments() { | |
global $wp_widget_factory; | |
remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) ); | |
} | |
/** | |
* Remove Emoji Styles and Scripts | |
*/ | |
public function remove_emoji() { | |
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
remove_action( 'embeded_head', 'print_emoji_detection_script' ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
} | |
/** | |
* Remove Feed Links | |
*/ | |
public function remove_feed() { | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
remove_action( 'wp_head', 'feed_links', 2 ); | |
remove_action( 'wp_head', 'wc_products_rss_feed' ); | |
} | |
/** | |
* Disable Feeds | |
*/ | |
public function redirect_feed() { | |
$this->remove_feed(); | |
add_action( 'do_feed', array( $this, '_redirect_feed' ), 1 ); | |
add_action( 'do_feed_rdf', array( $this, '_redirect_feed' ), 1 ); | |
add_action( 'do_feed_rss', array( $this, '_redirect_feed' ), 1 ); | |
add_action( 'do_feed_rss2', array( $this, '_redirect_feed' ), 1 ); | |
add_action( 'do_feed_atom', array( $this, '_redirect_feed' ), 1 ); | |
} | |
public function _redirect_feed() { | |
$this->redirect(); | |
} | |
/** | |
* Remove Link rel=shortlink from http | |
*/ | |
public function remove_server_shortlink() { | |
remove_action( 'template_redirect', 'wp_shortlink_header', 11 ); | |
} | |
/** | |
* Remove X-Pingback | |
*/ | |
public function remove_pingback() { | |
add_filter( 'wp_headers', array( $this, '_remove_pingback' ) ); | |
add_action( 'wp', array( $this, '__remove_pingback' ) ); | |
} | |
public function _remove_pingback( $headers ) { | |
if( isset( $headers['X-Pingback']) ) { | |
unset( $headers['X-Pingback'] ); | |
} | |
return $headers; | |
} | |
public function __remove_pingback() { | |
if ( function_exists( 'header_remove' ) ) { | |
header_remove( 'X-Pingback' ); | |
} | |
} | |
/** | |
* Remove X-Powered-By | |
*/ | |
public function remove_powered() { | |
if ( function_exists( 'header_remove' ) ) { | |
header_remove( 'x-powered-by' ); | |
} | |
add_action( 'wp', array( $this, '_remove_powered' ) ); | |
} | |
public function _remove_powered() { | |
if ( function_exists( 'header_remove' ) ) { | |
header_remove( 'x-powered-by' ); | |
} | |
} | |
/** | |
* Remove WP API Links and Scripts | |
*/ | |
public function remove_api_head() { | |
remove_action( 'wp_head', 'rest_output_link_wp_head' ); | |
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); | |
} | |
/** | |
* Remove WP API Link from HTTP Headers | |
*/ | |
public function remove_api_server() { | |
remove_action( 'template_redirect', 'rest_output_link_header', 11 ); | |
} | |
/** | |
* Totally Disable WP API Feature | |
*/ | |
public function disable_api() { | |
$this->remove_api_server(); | |
$this->remove_api_head(); | |
add_filter( 'json_enabled', '__return_false' ); | |
add_filter( 'json_jsonp_enabled', '__return_false' ); | |
add_filter( 'rest_enabled', '__return_false' ); | |
add_filter( 'rest_jsonp_enabled', '__return_false' ); | |
} | |
/** | |
* Remove Website/URL field | |
*/ | |
public function remove_comments_url() { | |
add_filter( 'comment_form_default_fields', array( $this, '_remove_comments_url' ) ); | |
} | |
public function _remove_comments_url( $fields ) { | |
if( isset( $fields['url'] ) ) | |
unset( $fields['url'] ); | |
return $fields; | |
} | |
/** | |
* Remove comment notes | |
*/ | |
public function remove_comments_notes() { | |
add_filter( 'comment_form_defaults', array( $this, '_remove_comments_notes' ) ) ; | |
} | |
public function _remove_comments_notes( $defaults ) { | |
$defaults['comment_notes_before'] = ''; | |
return $defaults; | |
} | |
/** | |
* Remove comment author link | |
*/ | |
public function remove_comments_author_link() { | |
add_filter( 'get_comment_author_link', array( $this, '_remove_comments_author_link' ) ) ; | |
} | |
public function _remove_comments_author_link( $author_link ) { | |
return strip_tags( $author_link ); | |
} | |
/** | |
* Remove comment auto linking | |
*/ | |
public function remove_comments_autolinking() { | |
remove_filter( 'comment_text', 'make_clickable', 9 ); | |
} | |
/** | |
* Remove date archives | |
*/ | |
public function remove_archives_date() { | |
add_action( 'template_redirect', array( $this, '_remove_archives_date' ) ); | |
} | |
public function _remove_archives_date() { | |
if( is_date() ) | |
$this->redirect(); | |
} | |
/** | |
* Remove author archives | |
*/ | |
public function remove_archives_author() { | |
add_action( 'template_redirect', array( $this, '_remove_archives_author' ) ); | |
} | |
public function _remove_archives_author() { | |
if( is_author() ) | |
$this->redirect(); | |
} | |
/** | |
* Remove tag archives | |
*/ | |
public function remove_archives_tag() { | |
add_action( 'template_redirect', array( $this, '_remove_archives_tag' ) ); | |
} | |
public function _remove_archives_tag() { | |
if( is_tag() ) | |
$this->redirect(); | |
} | |
/** | |
* Remove category archives | |
*/ | |
public function remove_archives_category() { | |
add_action( 'template_redirect', array( $this, '_remove_archives_category' ) ); | |
} | |
public function _remove_archives_category() { | |
if( is_category() ) | |
$this->redirect(); | |
} | |
/** | |
* Remove category archives | |
*/ | |
public function remove_archives_postformat() { | |
add_action( 'template_redirect', array( $this, '_remove_archives_postformat' ) ); | |
} | |
public function _remove_archives_postformat() { | |
if( is_tax( 'post_format' ) ) | |
$this->redirect(); | |
} | |
/** | |
* Remove search | |
*/ | |
public function remove_archives_search() { | |
add_action( 'template_redirect', array( $this, '_remove_archives_search' ) ); | |
} | |
public function _remove_archives_search() { | |
if( is_search() ) | |
$this->redirect(); | |
} | |
/** | |
* Remove attachments | |
*/ | |
public function remove_attachment() { | |
add_action( 'template_redirect', array( $this, '_remove_attachment' ) ); | |
} | |
public function _remove_attachment() { | |
if ( is_attachment() ){ | |
global $post; | |
$url = get_the_permalink( $post->post_parent ); | |
$this->redirect( $url ); | |
} | |
} | |
/** | |
* Remove DNS Prefetch Links | |
*/ | |
public function remove_dns_prefetch() { | |
remove_action( 'wp_head', 'wp_resource_hints', 2 ); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment