Created
March 16, 2019 02:05
-
-
Save kLOsk/d7399d295891ee38d3707643e361d8d6 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Disable header links | |
*/ | |
/** | |
* Clean up wp_head() | |
* | |
* Remove unnecessary <link>'s | |
* Remove inline CSS and JS from WP emoji support | |
* Remove inline CSS used by Recent Comments widget | |
* Remove inline CSS used by posts with galleries | |
* Remove self-closing tag | |
* | |
* You can enable/disable this feature in functions.php (or app/setup.php if you're using Sage): | |
* add_theme_support('soil-clean-up'); | |
*/ | |
function ggn_head_cleanup() { | |
// Originally from http://wpengineer.com/1438/wordpress-header/ | |
remove_action('wp_head', 'feed_links_extra', 3); | |
add_action('wp_head', 'ob_start', 1, 0); | |
add_action('wp_head', function () { | |
$pattern = '/.*' . preg_quote(esc_url(get_feed_link('comments_' . get_default_feed())), '/') . '.*[\r\n]+/'; | |
echo preg_replace($pattern, '', ob_get_clean()); | |
}, 3, 0); | |
remove_action('wp_head', 'rsd_link'); | |
remove_action('wp_head', 'wlwmanifest_link'); | |
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10); | |
remove_action('wp_head', 'wp_generator'); | |
remove_action('wp_head', 'wp_shortlink_wp_head', 10); | |
remove_action('wp_head', 'wp_oembed_add_discovery_links'); | |
remove_action('wp_head', 'wp_oembed_add_host_js'); | |
remove_action('wp_head', 'rest_output_link_wp_head', 10); | |
add_filter('use_default_gallery_style', '__return_false'); | |
add_filter('show_recent_comments_widget_style', '__return_false'); | |
} | |
add_action('init', 'ggn_head_cleanup'); | |
remove_action('wp_head', 'start_post_rel_link'); | |
remove_action('wp_head', 'index_rel_link'); | |
remove_action('wp_head', 'adjacent_posts_rel_link'); | |
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd'); | |
remove_action('template_redirect', 'rest_output_link_header', 11); | |
/** | |
* Disables trackbacks/pingbacks | |
* | |
* You can enable/disable this feature in functions.php (or app/setup.php if you're using Sage): | |
* add_theme_support('soil-disable-trackbacks'); | |
*/ | |
/** | |
* Disable pingback XMLRPC method | |
*/ | |
function ggn_filter_xmlrpc_method($methods) { | |
unset($methods['pingback.ping']); | |
return $methods; | |
} | |
add_filter('xmlrpc_methods', 'ggn_filter_xmlrpc_method', 10, 1); | |
/** | |
* Remove pingback header | |
*/ | |
function ggn_filter_headers($headers) { | |
if (isset($headers['X-Pingback'])) { | |
unset($headers['X-Pingback']); | |
} | |
return $headers; | |
} | |
add_filter('wp_headers', 'ggn_filter_headers', 10, 1); | |
/** | |
* Kill trackback rewrite rule | |
*/ | |
function ggn_filter_rewrites($rules) { | |
foreach ($rules as $rule => $rewrite) { | |
if (preg_match('/trackback\/\?\$$/i', $rule)) { | |
unset($rules[$rule]); | |
} | |
} | |
return $rules; | |
} | |
add_filter('rewrite_rules_array', 'ggn_filter_rewrites'); | |
/** | |
* Kill bloginfo('pingback_url') | |
*/ | |
function ggn_kill_pingback_url($output, $show) { | |
if ($show === 'pingback_url') { | |
$output = ''; | |
} | |
return $output; | |
} | |
add_filter('bloginfo_url', 'ggn_kill_pingback_url', 10, 2); | |
function no_self_ping( &$links ) { | |
$home = get_option( 'home' ); | |
foreach ( $links as $l => $link ) | |
if ( 0 === strpos( $link, $home ) ) | |
unset($links[$l]); | |
} | |
add_action( 'pre_ping', 'no_self_ping' ); | |
//Remove jquery migrate | |
function twf_remove_jquery_migrate( $scripts ) { | |
if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) { | |
$script = $scripts->registered['jquery']; | |
if ( $script->deps ) { // Check whether the script has any dependencies | |
$script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) ); | |
} | |
} | |
} | |
add_action( 'wp_default_scripts', 'twf_remove_jquery_migrate' ); | |
/** | |
* Disable XMLRPC call | |
*/ | |
function ggn_kill_xmlrpc($action) { | |
if ($action === 'pingback.ping') { | |
wp_die('Pingbacks are not supported', 'Not Allowed!', ['response' => 403]); | |
} | |
} | |
add_action('xmlrpc_call', 'ggn_kill_xmlrpc'); | |
/** | |
* Remove the WordPress version from RSS feeds | |
*/ | |
add_filter('the_generator', '__return_false'); | |
add_filter('xmlrpc_enabled', '__return_false'); | |
/** | |
* Disable the emoji's | |
*/ | |
function disable_emojis() { | |
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); | |
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); | |
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); | |
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' ); | |
add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 ); | |
} | |
add_action( 'init', 'disable_emojis' ); | |
/** | |
* Filter function used to remove the tinymce emoji plugin. | |
* | |
* @param array $plugins | |
* @return array Difference betwen the two arrays | |
*/ | |
function disable_emojis_tinymce( $plugins ) { | |
if ( is_array( $plugins ) ) { | |
return array_diff( $plugins, array( 'wpemoji' ) ); | |
} else { | |
return array(); | |
} | |
} | |
/** | |
* Remove emoji CDN hostname from DNS prefetching hints. | |
* | |
* @param array $urls URLs to print for resource hints. | |
* @param string $relation_type The relation type the URLs are printed for. | |
* @return array Difference betwen the two arrays. | |
*/ | |
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) { | |
if ( 'dns-prefetch' == $relation_type ) { | |
/** This filter is documented in wp-includes/formatting.php */ | |
$emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' ); | |
$urls = array_diff( $urls, array( $emoji_svg_url ) ); | |
} | |
return $urls; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment