Last active
June 20, 2023 09:03
-
-
Save 19h47/4b8d03bb0cd5942390830c3bc49422fe 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 | |
/** | |
* Plugin Name: WP Remove Actions | |
* Plugin URI: https://gist.github.com/19h47/4b8d03bb0cd5942390830c3bc49422fe | |
* Description: Mostly involved with cleaning up default WordPress cruft.. | |
* Version: 0.0.0 | |
* Author: Jérémy Levron | |
* Author URI: https://19h47.fr | |
* | |
* @package 19h47/wp-remove-actions | |
*/ | |
add_action( 'wp_loaded', 'wp_remove_actions_cleanup', 1 ); | |
add_filter( 'pre_get_shortlink', '__return_empty_string' ); | |
add_filter( 'wpseo_canonical', '__return_false' ); | |
add_action( 'init', 'wp_remove_actions_disable_emojis' ); | |
/** | |
* Disable emojicons. | |
* | |
* @see http://wordpress.stackexchange.com/questions/185577/disable-emojicons-introduced-with-wp-4-2 | |
* @return void | |
*/ | |
function wp_remove_actions_cleanup() { | |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
remove_action( 'wp_head', 'rsd_link' ); | |
remove_action( 'wp_head', 'wlwmanifest_link' ); | |
remove_action( 'wp_head', 'wp_shortlink_wp_head' ); | |
remove_action( 'wp_head', 'wp_generator' ); | |
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); | |
remove_action( 'wp_head', 'rest_output_link_wp_head' ); | |
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); | |
remove_action( 'wp_head', 'rel_canonical' ); | |
remove_action( 'wp_head', 'feed_links', 2 ); | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); | |
remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); | |
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); | |
} | |
/** | |
* Hide extranneous dashboard widgets | |
* | |
* @return void | |
*/ | |
function wp_remove_actions_remove_dashboard_widgets() : void { | |
global $wp_meta_boxes; | |
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] ); | |
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links'] ); | |
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now'] ); | |
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'] ); | |
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts'] ); | |
unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments'] ); | |
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] ); | |
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary'] ); | |
unset( $wp_meta_boxes['dashboard']['normal']['core']['yoast_db_widget'] ); | |
} | |
/** | |
* Disable the emoji's | |
*/ | |
function wp_remove_actions_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', 'wp_remove_actions_disable_emojis_tinymce' ); | |
add_filter( 'wp_resource_hints', 'wp_remove_actions_disable_emojis_remove_dns_prefetch', 10, 2 ); | |
} | |
/** | |
* Filter function used to remove the tinymce emoji plugin. | |
* | |
* @param array $plugins Plugins. | |
* @return array Difference betwen the two arrays | |
*/ | |
function wp_remove_actions_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 wp_remove_actions_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