PHP
<?php
/**
* WordPress Unbloater - Optimierte Version für functions.php
* Fokus: Performance, Sicherheit, Bereinigung
*/
// ===== BACKEND CLEANUP =====
// Update-Benachrichtigungen für Nicht-Admins entfernen
add_action('admin_head', function () {
if (!current_user_can('update_core')) {
remove_action('admin_notices', 'update_nag', 3);
}
}, 1);
// Auto-Updates & Datei-Bearbeitung deaktivieren
define('AUTOMATIC_UPDATER_DISABLED', true);
define('DISALLOW_FILE_EDIT', true);
define('CORE_UPGRADE_SKIP_NEW_BUNDLED', true);
define('WP_POST_REVISIONS', 5);
define('EMPTY_TRASH_DAYS', 7);
add_filter('auto_update_plugin', '__return_false');
add_filter('auto_update_theme', '__return_false');
add_filter('plugins_auto_update_enabled', '__return_false');
add_filter('themes_auto_update_enabled', '__return_false');
// Sonstiges Backend
add_filter('wp_is_application_passwords_available', '__return_false');
add_filter('admin_email_check_interval', '__return_false');
add_filter('login_display_language_dropdown', '__return_false');
add_filter('admin_footer_text', '__return_false');
// Adminbar aufräumen
add_action('admin_bar_menu', function ($wp_admin_bar) {
$wp_admin_bar->remove_menu('wp-logo');
$wp_admin_bar->remove_menu('wpseo-menu');
$wp_admin_bar->remove_menu('rank-math');
}, 999);
// ===== XML-RPC & REST API =====
add_filter('xmlrpc_enabled', '__return_false');
add_filter('wp_headers', function ($headers) {
unset($headers['X-Pingback'], $headers['x-pingback']);
return $headers;
});
add_filter('pings_open', '__return_false', 9999);
add_filter('xmlrpc_methods', function ($methods) {
unset($methods['pingback.ping'], $methods['pingback.extensions.getPingbacks']);
return $methods;
});
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
add_action('init', function () {
if (basename($_SERVER['SCRIPT_FILENAME']) === 'xmlrpc.php') {
header('HTTP/1.1 403 Forbidden');
exit('403 Forbidden');
}
});
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('template_redirect', 'rest_output_link_header', 11);
// ===== FRONTEND CLEANUP =====
add_action('wp_enqueue_scripts', function () {
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('classic-theme-styles');
wp_deregister_style('classic-theme-styles');
wp_dequeue_script('wc-cart-fragments');
}, 100);
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_shortlink_wp_head', 10);
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'wp_resource_hints', 2);
// Versionen aus Skript-URLs entfernen
add_filter('style_loader_src', 'remove_ver_param', 9999);
add_filter('script_loader_src', 'remove_ver_param', 9999);
function remove_ver_param($src) {
return is_admin() ? $src : remove_query_arg('ver', $src);
}
// Emojis deaktivieren
add_action('init', function () {
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', function ($plugins) {
return is_array($plugins) ? array_diff($plugins, ['wpemoji']) : [];
});
add_filter('emoji_svg_url', '__return_false');
});
// Kommentar-JS nur wenn nötig
add_action('wp_print_scripts', function () {
if (!(is_singular() && comments_open() && get_comments_number() > 0 && get_option('thread_comments'))) {
wp_dequeue_script('comment-reply');
}
}, 100);
// Kommentar-Links deaktivieren
remove_filter('comment_text', 'make_clickable', 9);
// Heartbeat reduzieren
add_filter('heartbeat_settings', function ($settings) {
$settings['interval'] = 60;
return $settings;
});
// Favicon normalisieren
add_filter('get_site_icon_url', function ($url) {
return includes_url('images/w-logo-blue-white-bg.png') === $url ? '' : $url;
}, 10);
// Login-Seite Branding
add_filter('login_headerurl', function () {
return home_url();
});
add_filter('login_headertext', function () {
return get_bloginfo('name');
});
// ===== BLOCK EDITOR =====
remove_action('enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets');
remove_theme_support('core-block-patterns');
remove_theme_support('block-templates');
// Vollbildmodus und Willkommensguide deaktivieren
add_action('enqueue_block_editor_assets', function () {
wp_add_inline_script('wp-data', "window.addEventListener('DOMContentLoaded', function() {
const wpData = wp.data;
if (wpData.select('core/edit-post').isFeatureActive('fullscreenMode')) {
wpData.dispatch('core/edit-post').toggleFeature('fullscreenMode');
}
if (wpData.select('core/preferences').get('core/edit-widgets', 'welcomeGuide')) {
wpData.dispatch('core/preferences').toggle('core/edit-widgets', 'welcomeGuide');
}
if (wpData.select('core/edit-post').isFeatureActive('welcomeGuide')) {
wpData.dispatch('core/edit-post').toggleFeature('welcomeGuide');
}
});");
});
// ===== PLUGIN-TWEAKS =====
// ACF Admin verstecken
add_filter('acf/settings/show_admin', '__return_false');
// Autoptimize
add_filter('autoptimize_filter_toolbar_show', '__return_false');
add_filter('autoptimize_filter_main_imgopt_plug_notice', '__return_empty_string');
// Rank Math
add_action('rank_math/whitelabel', '__return_true');
add_filter('rank_math/sitemap/remove_credit', '__return_true');
add_filter('rank_math/link/remove_class', '__return_true');
// SearchWP
add_filter('searchwp\admin\dashboard_widgets\statistics', '__return_false');
add_filter('searchwp\options\dashboard_stats_link', '__return_false');
add_filter('searchwp\admin_bar', '__return_false');
add_filter('searchwp\admin_menu\position', fn() => 98);
add_filter('searchwp\options\settings_screen', '__return_false');
// The SEO Framework
add_filter('the_seo_framework_indicator', '__return_false');
add_filter('the_seo_framework_metabox_context', fn() => 'side');
// WooCommerce
add_filter('woocommerce_helper_suppress_connect_notice', '__return_true');
add_filter('woocommerce_helper_suppress_admin_notices', '__return_true');
// SkyVerge Dashboard entfernen
add_action('admin_menu', fn() => remove_menu_page('skyverge'), 99);
add_action('admin_enqueue_scripts', fn() => wp_dequeue_style('sv-wordpress-plugin-admin-menus'), 20);
// ===== SICHERHEITSHEADER =====
add_action('send_headers', function () {
header('X-Frame-Options: SAMEORIGIN');
header('X-Content-Type-Options: nosniff');
header('X-XSS-Protection: 1; mode=block');
header('Referrer-Policy: strict-origin-when-cross-origin');
header('Permissions-Policy: accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()');
// Optional: Nur aktivieren, wenn HTTPS aktiv ist
// header('Strict-Transport-Security: max-age=31536000; includeSubDomains; preload');
// Optional: Content Security Policy anpassen!
// header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src * data:; font-src 'self';");
});