Skip to content

Instantly share code, notes, and snippets.

@bewho
Forked from designrubenz/functions.php
Created June 8, 2018 08:06
Show Gist options
  • Save bewho/cc33d3f9d2d69d6ac884658393e211b8 to your computer and use it in GitHub Desktop.
Save bewho/cc33d3f9d2d69d6ac884658393e211b8 to your computer and use it in GitHub Desktop.
Wordpress: reduce to the max
<?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_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;
}
// disable embedding posts from other people's blogs/websites
function my_deregister_scripts(){
wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );
// disable displaying login errors
add_filter( 'login_errors', create_function( '$a', "return null;" ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment