Last active
November 25, 2020 07:51
-
-
Save designrubenz/a909de19dbf6aa385cdb77f0b78fb2b3 to your computer and use it in GitHub Desktop.
Wordpress: reduce to the max
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 | |
function wp_customize_admin_menu() { | |
remove_menu_page( 'edit.php' ); | |
remove_menu_page( 'edit-comments.php' ); | |
remove_submenu_page( 'themes.php', 'theme-editor.php' ); | |
remove_submenu_page( 'plugins.php', 'plugin-editor.php' ); | |
remove_submenu_page( 'tools.php', 'tools.php' ); | |
remove_submenu_page( 'tools.php', 'import.php' ); | |
remove_submenu_page( 'options-general.php', 'options-discussion.php' ); | |
} | |
add_action('admin_init', 'wp_customize_admin_menu' ); | |
function wp_customize_default_meta_boxes() { | |
remove_meta_box( 'authordiv', 'page', 'normal' ); | |
remove_meta_box( 'commentstatusdiv', 'page', 'normal' ); | |
remove_meta_box( 'commentsdiv', 'page', 'normal' ); | |
remove_meta_box( 'postexcerpt', 'page', 'normal' ); | |
remove_meta_box( 'slugdiv', 'page', 'normal' ); | |
remove_meta_box( 'trackbacksdiv', 'page', 'normal' ); | |
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'normal' ); | |
} | |
add_action('admin_init', 'wp_customize_default_meta_boxes' ); | |
function wp_remove_admin_bar_links() { | |
global $wp_admin_bar; | |
$wp_admin_bar->remove_menu( 'comments' ); | |
$wp_admin_bar->remove_menu( 'new-user' ); | |
} | |
add_action( 'wp_before_admin_bar_render', 'wp_remove_admin_bar_links' ); | |
function wp_init() { | |
add_theme_support( 'post-thumbnails' ); | |
remove_theme_support( 'comments' ); | |
remove_post_type_support( 'post', 'post-formats' ); | |
remove_post_type_support( 'post', 'custom-fields' ); | |
remove_post_type_support( 'post', 'comments' ); | |
remove_post_type_support( 'post', 'author' ); | |
remove_post_type_support( 'post', 'trackbacks' ); | |
remove_post_type_support( 'page', 'custom-fields' ); | |
remove_post_type_support( 'page', 'comments' ); | |
remove_post_type_support( 'page', 'author' ); | |
remove_post_type_support( 'page', 'trackbacks' ); | |
add_post_type_support( 'page', 'thumbnail' ); | |
/* Remove 'subscriber' role */ | |
remove_role( 'subscriber' ); | |
remove_action( 'wp_head', 'wp_print_scripts' ); | |
remove_action( 'wp_head', 'wp_print_head_scripts', 9 ); | |
remove_action( 'wp_head', 'wp_enqueue_scripts', 1 ); | |
add_action( 'wp_footer', 'wp_print_scripts', 5 ); | |
add_action( 'wp_footer', 'wp_enqueue_scripts', 5 ); | |
add_action( 'wp_footer', 'wp_print_head_scripts', 5 ); | |
/* Remove feed links from head section */ | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
remove_action( 'wp_head', 'feed_links', 2 ); | |
remove_action( 'wp_head', 'rsd_link' ); | |
remove_action( 'wp_head', 'wp_resource_hints', 2 ); | |
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); | |
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ); | |
remove_action( 'wp_head', 'wlwmanifest_link'); | |
remove_action( 'wp_head', 'wp_shortlink_wp_head'); | |
remove_action( 'wp_head', 'wp_generator' ); | |
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
} | |
add_action( 'init', 'wp_init' ); | |
add_filter('rest_enabled', '__return_false'); | |
add_filter('rest_jsonp_enabled', '__return_false'); | |
add_filter('jpeg_quality', create_function( '', 'return 85;' ) ); | |
function wp_disable_feed() { | |
wp_die(); | |
} | |
add_action('do_feed', 'wp_disable_feed', 1); | |
add_action('do_feed_rdf', 'wp_disable_feed', 1); | |
add_action('do_feed_rss', 'wp_disable_feed', 1); | |
add_action('do_feed_rss2', 'wp_disable_feed', 1); | |
add_action('do_feed_atom', 'wp_disable_feed', 1); | |
function wp_enqueue_scripts() { | |
if ( !is_admin() ) { | |
wp_deregister_script( 'jquery' ); | |
} | |
wp_enqueue_script( | |
'jquery', | |
get_template_directory_uri() . '/assets/javascripts/jquery.min.js' | |
); | |
} | |
add_action( 'wp_enqueue_scripts', 'wp_enqueue_scripts' ); | |
function wp_customice_tiny_mce( $in ) { | |
$in['paste_remove_styles'] = true; | |
$in['paste_remove_spans'] = true; | |
$in['apply_source_formatting'] = false; | |
$in['block_formats'] = "Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3"; | |
$in['toolbar1'] = 'formatselect,bullist,numlist,bold,italic,underline,strikethrough,alignleft,aligncenter,alignright,alignjustify,link,unlink,charmap,undo,redo,wp_help '; | |
$in['toolbar2'] = ''; | |
$in['toolbar3'] = ''; | |
$in['toolbar4'] = ''; | |
return $in; | |
} | |
add_filter( 'tiny_mce_before_init', 'wp_customice_tiny_mce' ); | |
// Disable emojis | |
function disable_emoji_feature() { | |
// Prevent Emoji from loading on the front-end | |
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
// Remove from admin area also | |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
// Remove from RSS feeds also | |
remove_filter( 'the_content_feed', 'wp_staticize_emoji'); | |
remove_filter( 'comment_text_rss', 'wp_staticize_emoji'); | |
// Remove from Embeds | |
remove_filter( 'embed_head', 'print_emoji_detection_script' ); | |
// Remove from emails | |
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); | |
// Disable from TinyMCE editor. Currently disabled in block editor by default | |
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' ); | |
/** Finally, disable it from the database also, | |
* to prevent characters from converting | |
* Earlier, there was a setting under Writings to do this | |
* It is not ideal to get & update it here - but it works for now | |
*/ | |
if( (int) get_option('use_smilies') === 1 ) { | |
update_option( 'use_smilies', 0 ); | |
} | |
} | |
function disable_emojis_tinymce( $plugins ) { | |
if( is_array($plugins) ) { | |
$plugins = array_diff( $plugins, array( 'wpemoji' ) ); | |
} | |
return $plugins; | |
} | |
add_action('init', 'disable_emoji_feature'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment