Last active
December 1, 2025 20:36
-
-
Save nathaningram/d97b0d74631d5f22ec5aec8d39162eda to your computer and use it in GitHub Desktop.
Starter Site 2025 - MU Core
This file contains hidden or 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: Custom Core Functions | |
| Description: Customize the WP Core | |
| Version: 1.0 | |
| Plugin URI: https://wpnathan.com | |
| Author: Nathan Ingram | |
| Author URI: https://wpnathan.com | |
| License: GPL2 | |
| */ | |
| // Security Check | |
| if (!defined('ABSPATH')) { | |
| die(); | |
| } | |
| //Disable Automatic Theme and Plugin Updates | |
| add_filter( 'plugins_auto_update_enabled', '__return_false' ); | |
| add_filter( 'themes_auto_update_enabled', '__return_false' ); | |
| // Disable Auto Update Emails for Themes and Plugins | |
| add_filter( 'auto_plugin_update_send_email', '__return_false' ); | |
| add_filter( 'auto_theme_update_send_email', '__return_false' ); | |
| // Disable Emojis | |
| function bww_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', 'bww_disable_emojis_tinymce' ); | |
| add_filter( 'wp_resource_hints', 'bww_disable_emojis_remove_dns_prefetch', 10, 2 ); | |
| } | |
| add_action( 'init', 'bww_disable_emojis' ); | |
| function bww_disable_emojis_tinymce( $plugins ) { | |
| if ( is_array( $plugins ) ) { | |
| return array_diff( $plugins, array( 'wpemoji' ) ); | |
| } else { | |
| return array(); | |
| } | |
| } | |
| function bww_disable_emojis_remove_dns_prefetch( $urls, $relation_type ) { | |
| if ( 'dns-prefetch' == $relation_type ) { | |
| $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; | |
| } | |
| // Disables feeds | |
| function bww_clean_feeds() { // Redirects all feeds to home page. | |
| $url = site_url(); | |
| wp_redirect( $url ); | |
| } | |
| add_action( 'do_feed', 'bww_clean_feeds', 1 ); | |
| add_action( 'do_feed_rdf', 'bww_clean_feeds', 1 ); | |
| add_action( 'do_feed_rss', 'bww_clean_feeds', 1 ); | |
| add_action( 'do_feed_rss2', 'bww_clean_feeds', 1 ); | |
| add_action( 'do_feed_atom', 'bww_clean_feeds', 1 ); | |
| add_action( 'do_feed_rss2_comments', 'bww_clean_feeds', 1 ); | |
| add_action( 'do_feed_atom_comments', 'bww_clean_feeds', 1 ); | |
| // Clean Up WP_Head | |
| remove_action( 'wp_head', 'wp_generator' ); // Removes WordPress version. | |
| remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); // Removes shortlink. | |
| remove_action( 'wp_head', 'rsd_link' ); // Removes Really Simple Discovery link. | |
| remove_action( 'wp_head', 'feed_links', 2 ); // Removes RSS feed links. | |
| remove_action( 'wp_head', 'feed_links_extra', 3 ); // Removes all extra RSS feed links. | |
| remove_action( 'wp_head', 'wlwmanifest_link' ); // Removes wlwmanifest.xml. | |
| remove_action( 'wp_head', 'wp_resource_hints', 2 ); // Removes meta rel=dns-prefetch href=//s.w.org | |
| remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Removes relational links for the posts. | |
| remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ); // Removes oEmbeds. | |
| // Disable New User Reg Emails to Admin | |
| add_action('init', 'ni_init'); | |
| //Initializes custom user notification handlers | |
| function ni_init() { | |
| // Unhook the default user notification actions | |
| remove_action('register_new_user', 'wp_send_new_user_notifications'); | |
| remove_action('edit_user_created_user', 'wp_send_new_user_notifications', 10); | |
| // Hook up the custom notification function | |
| add_action('register_new_user', 'ni_send_user_notification'); | |
| add_action('edit_user_created_user', 'ni_send_user_notification', 10, 2); | |
| } | |
| // Send new user notifications based on the specified context. | |
| function ni_send_user_notification(int $userId, string $context = 'both') { | |
| // If the context is 'admin', we do nothing. | |
| if ('admin' === $context) { | |
| return; | |
| } | |
| // Notify only the user in cases of 'both' or 'user'. | |
| wp_send_new_user_notifications($userId, 'user'); | |
| } | |
| // Disable User Password Change Emails to Admin | |
| if ( ! function_exists( 'wp_password_change_notification' ) ) { | |
| function wp_password_change_notification( $user ) { | |
| return; | |
| } | |
| } | |
| // Sort Settings and Tools Menu Items Alphabetically | |
| function bww_sort_settings_tools_menu_items_alphabetically() { | |
| global $submenu; | |
| $menus_to_sort = array( | |
| 'options-general.php', // Settings menu | |
| 'tools.php' // Tools menu | |
| ); | |
| foreach ($menus_to_sort as $menu_slug) { | |
| // Check if the menu exists | |
| if (isset($submenu[$menu_slug]) && is_array($submenu[$menu_slug])) { | |
| // Sort the items under the menu alphabetically | |
| usort($submenu[$menu_slug], function ($a, $b) use ($menu_slug) { | |
| // Ensure both array elements have the 0-index set and are strings | |
| if (isset($a[0]) && isset($b[0]) && is_string($a[0]) && is_string($b[0])) { | |
| // Prioritize 'General' item if on Settings menu | |
| if ($menu_slug === 'options-general.php') { | |
| if (isset($a[2]) && $a[2] === $menu_slug) { | |
| return -1; | |
| } | |
| if (isset($b[2]) && $b[2] === $menu_slug) { | |
| return 1; | |
| } | |
| } | |
| return strcasecmp($a[0], $b[0]); | |
| } | |
| return 0; | |
| }); | |
| // Update the href of the first link to go to the corresponding page | |
| if (isset($submenu[$menu_slug][0]) && is_array($submenu[$menu_slug][0])) { | |
| $submenu[$menu_slug][0][2] = $menu_slug; | |
| } | |
| } | |
| } | |
| } | |
| add_action('admin_menu', 'bww_sort_settings_tools_menu_items_alphabetically', 999); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment