Skip to content

Instantly share code, notes, and snippets.

@ankurk91
Last active October 9, 2024 00:37
Show Gist options
  • Save ankurk91/39318544e05d7f21858e to your computer and use it in GitHub Desktop.
Save ankurk91/39318544e05d7f21858e to your computer and use it in GitHub Desktop.
Power WordPress Tweaks [Use at your own risk] ⚠️
<?php
/*
Plugin Name: Power WP Tweaks
Plugin URI: http://ankurk91.github.io/
Description: Some common tweaks to optimize WP Site
Version: 1.0
Author: ankurk91
Author URI: http://ankurk91.github.io/
License: MIT
*/
/*Note: This plugin has no interface.
So if you want to change something, then go inside and change the code.*/
/**
* ################################################################
* Warning : Use at your own risk
* Please test them in development and then use in production
* ################################################################
*/
/* no direct access */
if (!defined('ABSPATH')) exit;
class Ank_WP_FrontEnd_Tweaks_MU_Plugin
{
function __construct()
{
/* Add short-code support to text widget. */
add_filter('widget_text', 'do_shortcode');
//remove wp default comment widget css
add_filter('show_recent_comments_widget_style', '__return_false', 9);
//Unlink urls in comment text
remove_filter('comment_text', 'make_clickable', 9);
//remove links from head (front end)
add_action('init', array($this, 'remove_head_links'));
//remove ping-back headers
add_filter('wp_headers', array($this, 'remove_x_pingback'));
//tell me database queries in footer
add_action('wp_footer', array($this, 'get_page_speed'), 99);
//hide (replace) admin login errors
add_filter('login_errors', array($this, 'replace_login_page_msgs'));
//add_filter( 'login_headerurl', 'ank_login_logo_url' );
//add_filter( 'login_headertitle', 'ank_login_logo_url_title' );
//remove shake effect from login page
add_action('login_head', array($this, 'login_head_shake'));
//completely remove login page logo
add_action('login_footer', array($this, 'remove_login_logo'), 9);
//remove wp version from every where
add_filter('the_generator', array($this, 'no_wp_generators'));
//remove wp default widgets
add_action('widgets_init', array($this, 'remove_wp_inbuilt_widgets'), 9);
// add_filter( 'comment_class' , array($this,'remove_comment_author_class' ));
//completely remove admin bar from front end
add_filter('show_admin_bar', '__return_false');
//remove emoji in wp 4.2+
add_action('init', array($this, 'remove_emoji_js_css'));
} //end construct
/* remove links from page head */
function remove_head_links()
{
remove_action('wp_head', 'rsd_link'); //edit uri
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'wp_generator');
}
function remove_emoji_js_css()
{
//remove emoji in wp v4.2+
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
}
function remove_x_pingback($headers)
{
unset($headers['X-Pingback']);
return $headers;
}
function get_page_speed()
{
printf('<!-- %d queries in %.3f seconds, using %.2fMB memory -->',
get_num_queries(),
timer_stop(0, 3),
memory_get_usage(true) / 1024 / 1024
);
}
function replace_login_page_msgs()
{
return 'Error processing request. Please try again.';
}
//change login logo url
function ank_login_logo_url()
{
return get_bloginfo('url');
}
//change login logo hover title
function ank_login_logo_url_title()
{
return get_bloginfo('name');
}
//remove login shake effect
function login_head_shake()
{
remove_action('login_head', 'wp_shake_js', 12);
}
//remove login logo completely
function remove_login_logo()
{
//using javascript
?>
<script>var LG = document.getElementById("login");
LG.getElementsByTagName("h1")[0].remove();</script>
<?php
}
function no_wp_generators()
{ //won't show wp version no where
return '';
}
function remove_wp_inbuilt_widgets()
{
unregister_widget('WP_Widget_Meta');
}
// Remove admin name in comments class
// Source: http://www.wprecipes.com/wordpress-hack-remove-admin-name-in-comments-class
function remove_comment_author_class($classes)
{
foreach ($classes as $key => $class) {
if (strstr($class, "comment-author-")) {
unset($classes[$key]);
}
}
return $classes;
}
} //class ends
new Ank_WP_FrontEnd_Tweaks_MU_Plugin;
//lets keep admin-area tweaks here
class Ank_WP_Admin_Tweaks_MU_Plugin
{
function __construct()
{
//replace admin footer text
add_filter('admin_footer_text', array($this, 'change_footer_admin'));
//translate howdy to welcome
add_filter('gettext', array($this, 'change_howdy'), 10, 3);
//a developer info wigdet to dashboard
add_action('wp_dashboard_setup', array($this, 'add_dashboard_widgets'), 99);
//add a custom support menu to admin_bar
add_action('admin_bar_menu', array($this, 'add_admin_bar_link'), 999);
//remove wordpress menu from wp admin bar
add_action('admin_bar_menu', array($this, 'remove_admin_bar_menu'), 99);
//add_filter("mce_buttons_3", array($this,'add_more_buttons_editor'));
//add_filter( 'admin_title', array( $this, 'filter_admin_title' ) );
add_action('admin_init', array($this, 'remove_dashboard_meta'));
//dashboard
remove_action('welcome_panel', 'wp_welcome_panel');
//remove theme menu
add_action('admin_menu', array($this, 'remove_theme_menus'));
add_action('init', array($this, 'remove_emoji_admin'));
}
function remove_emoji_admin()
{
// Remove from comment feed and RSS
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
// Remove from emails
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
// Remove from admin area
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
}
//change wp-admin footer text
function change_footer_admin()
{
?>Developed by <a target="_blank" href="http://ankurk91.github.io/">Ankur</a>
<?php }
//change howdy to welcome
function change_howdy($translated, $text, $domain)
{
if (!is_admin() || 'default' != $domain)
return $translated;
if (false !== strpos($translated, 'Howdy'))
return str_replace('Howdy', 'Welcome', $translated);
return $translated;
}
//* Add theme info box into WordPress Dashboard
function add_dashboard_widgets()
{
wp_add_dashboard_widget('wp_dashboard_dev_info_widget', 'Website Details', array($this, 'dev_info_widget'));
}
function dev_info_widget()
{ ?>
<ul>
<li><strong><i class='dashicons dashicons-businessman'>&emsp;</i> Developed By:</strong> Ankur</li>
<li><strong><i class='dashicons dashicons-admin-site'>&emsp;</i> Website:</strong>
<a target='_blank' href='https://ankurk91.github.io/'>https://ankurk91.github.io/</a>
</li>
</ul>
<?php }
//adding a custom link to admin top bar
function add_admin_bar_link($wp_admin_bar)
{
$wp_admin_bar->add_menu(array(
'id' => 'ank_wp_support',
'title' => '<span class="ab-icon dashicons dashicons-external"></span>Support',
'href' => 'https://ankurk91.github.io/',
'meta' => array('title' => 'Need Help ?', 'target' => '_blank'),
)
);
}
//remove wp menu from admin bar
function remove_admin_bar_menu($wp_admin_bar)
{
$wp_admin_bar->remove_menu('wp-logo');
}
function add_more_buttons_editor($buttons)
{
$buttons[] = 'hr';
$buttons[] = 'superscript';
$buttons[] = 'subscript';
$buttons[] = 'fontsizeselect';
$buttons[] = 'styleselect';
$buttons[] = 'fontselect';
$buttons[] = 'backcolor';
$buttons[] = 'wp_page';
return $buttons;
}
//remove wordpress from title bar
function filter_admin_title($title)
{
if (strpos($title, ' WordPress')) {
$title = str_replace(" &#8212; WordPress", "", $title);
}
return $title;
}
//remove dashboard widgets
function remove_dashboard_meta()
{
//comment the lines what u need
//remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
//remove_meta_box( 'dashboard_activity', 'dashboard', 'side' );
//remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
//remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); //at a glance
//remove_meta_box( 'dashboard_browser_nag', 'dashboard', 'normal' );
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); //Incoming Links
remove_meta_box('dashboard_primary', 'dashboard', 'side'); //WordPress.com Blog
remove_meta_box('dashboard_secondary', 'dashboard', 'side'); //Other WordPress News
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
}
function remove_theme_menus()
{
remove_submenu_page('themes.php', 'themes.php');
}
}//end class
if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
new Ank_WP_Admin_Tweaks_MU_Plugin();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment