Skip to content

Instantly share code, notes, and snippets.

@rosswintle
Created February 1, 2019 17:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosswintle/14882526ef018cccd75a5c03a842e201 to your computer and use it in GitHub Desktop.
Save rosswintle/14882526ef018cccd75a5c03a842e201 to your computer and use it in GitHub Desktop.
WordPress Cleanup hooks
<?php
/**
* Plugin Name: Wordpress Cleanup
*/
namespace WordPress_Cleanup;
/**
* Change filters here to control what this does
*/
add_action('init', __NAMESPACE__ . '\remove_unused_header_items');
add_filter('post_comments_feed_link', __NAMESPACE__ . '\remove_comment_feeds');
add_action('login_enqueue_scripts', __NAMESPACE__ . '\remove_wordpress_logo_from_login');
add_filter('show_admin_bar', __NAMESPACE__ . '\remove_admin_toolbar');
add_action('init', __NAMESPACE__ . '\disable_emoticons');
add_filter('tiny_mce_plugins', __NAMESPACE__ . '\disable_tinymce_emoticons');
add_action('admin_init', __NAMESPACE__ . '\remove_dashboard_items');
add_filter('admin_footer_text', __NAMESPACE__ . '\remove_built_with_from_footer', 9999);
add_filter('update_footer', __NAMESPACE__ . '\remove_wordpress_version_from_footer', 9999);
add_filter('login_errors', __NAMESPACE__ . '\generic_login_error');
add_filter('screen_options_show_screen', __NAMESPACE__ . '\screen_options_capability');
add_action('admin_head', __NAMESPACE__ . '\remove_help');
add_filter('wp_headers', __NAMESPACE__ . '\remove_pingback_headers');
/* Remove welcome box */
remove_action('welcome_panel', 'wp_welcome_panel');
/* Disable all automatic core updates */
//add_filter('automatic_updater_disabled', '__return_true');
/* Disable all core updates */
//add_filter('auto_update_core', '__return_false');
/* Disable automatic plugin updates */
add_filter('auto_update_plugin', '__return_false');
/* Disable automatic theme updates */
add_filter('auto_update_theme', '__return_false');
/* Remove XMLRPC */
add_filter('wp_xmlrpc_server_class', '__return_false');
add_filter('xmlrpc_enabled', '__return_false');
/**
* Disable indexing (requires phpdotenv)
*/
if(function_exists('getenv')) {
if(getenv('WP_ENV') !== 'production' && !is_admin()) {
add_action('pre_option_blog_public', '__return_zero');
}
}
/**
* Remove unused header items
*/
function remove_unused_header_items() {
$actions = array(
'feed_links_extra',
'wp_generator',
'rsd_link',
'wlwmanifest_link',
'rest_output_link_wp_head',
'wp_oembed_add_discovery_links',
'wp_oembed_add_host_js'
);
foreach($actions as $action) {
remove_action('wp_head', $action);
}
}
/**
* Remove comment feeds
*/
function remove_comment_feeds() {
return null;
}
/**
* Remove Wordpress logo from login
*/
add_action('login_enqueue_scripts',
function remove_wordpress_logo_from_login() { ?>
<style>
.login h1 a {
background-image: none;
}
</style>
<?php }
/**
* Remove the admin tool bar
*/
function remove_admin_toolbar() {
return false;
}
/**
* Disable emoticons
*/
function disable_emoticons() {
remove_action('admin_print_styles', 'print_emoji_styles');
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_filter('wp_mail', 'wp_staticize_emoji_for_email');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
}
/**
* Disable TinyMCE emoticons
*/
function disable_tinymce_emoticons($plugins) {
if (is_array($plugins)) {
return array_diff($plugins, array('wpemoji'));
} else {
return array();
}
}
/**
* Remove dashboard items
*/
function remove_dashboard_items() {
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
remove_meta_box('dashboard_plugins', 'dashboard', 'normal');
remove_meta_box('dashboard_primary', 'dashboard', 'normal');
remove_meta_box('dashboard_secondary', 'dashboard', 'normal');
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
//remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
//remove_meta_box('dashboard_activity', 'dashboard', 'normal');
}
/**
* Remove built with message from admin footer
*/
function remove_built_with_from_footer() {
return '&nbsp;';
}
/**
* Remove Wordpress version from admin footer
*/
function remove_wordpress_version_from_footer() {
return ' ';
}
/**
* Make the Wordpress login error more generic to help prevent people brute forcing
*/
function generic_login_error() {
return __('Username/Password is incorrect');
}
/**
* Remove screen options for non-admins
*/
function screen_options_capability() {
return current_user_can('manage_options');
}
/**
* Remove help section from all pages
*/
function remove_help() {
$screen = get_current_screen();
$screen->remove_help_tabs();
}
/**
* Remove X-Pingback headers
*/
function remove_pingback_headers($headers) {
unset($headers['X-Pingback']);
return $headers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment