function optimize_non_display_features() {
// Disable Emojis
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
add_filter('tiny_mce_plugins', function($plugins) {
return is_array($plugins) ? array_diff($plugins, array('wpemoji')) : array();
});
add_filter('wp_resource_hints', function($urls, $relation_type) {
if ('dns-prefetch' === $relation_type) {
$emoji_url = 'https://s.w.org/images/core/emoji/';
$urls = array_diff($urls, array($emoji_url));
}
return $urls;
}, 10, 2);
// Disable Embeds
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('wp_head', 'wp_oembed_add_host_js');
add_filter('embed_oembed_discover', '__return_false');
remove_action('rest_api_init', 'wp_oembed_register_route');
add_filter('tiny_mce_plugins', function($plugins) {
return is_array($plugins) ? array_diff($plugins, array('wpembed')) : array();
});
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
add_filter('rewrite_rules_array', function($rules) {
foreach ($rules as $rule => $rewrite) {
if (false !== strpos($rewrite, 'embed=true')) {
unset($rules[$rule]);
}
}
return $rules;
});
// Remove Shortlink
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('template_redirect', 'wp_shortlink_header');
// Remove RSS Feed Links
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'feed_links', 2);
// Disable Password Strength Meter
add_action('wp_print_scripts', function() {
wp_dequeue_script('zxcvbn-async');
});
// Disable Comments
add_action('init', function() {
remove_post_type_support('post', 'comments');
remove_post_type_support('page', 'comments');
add_filter('comments_open', '__return_false');
add_filter('pings_open', '__return_false');
});
// Remove Comment URLs
add_filter('comment_form_default_fields', function($fields) {
if (isset($fields['url'])) {
unset($fields['url']);
}
return $fields;
});
// Disable Self Pingbacks
add_action('pre_ping', function(&$links) {
foreach ($links as $key => $link) {
if (strpos($link, home_url()) === 0) {
unset($links[$key]);
}
}
});
// Disable XML-RPC
add_filter('xmlrpc_enabled', '__return_false');
// Hide WP Version
remove_action('wp_head', 'wp_generator');
// Remove wlwmanifest Link
remove_action('wp_head', 'wlwmanifest_link');
// Remove RSD Link
remove_action('wp_head', 'rsd_link');
// Remove jQuery Migrate
add_action('wp_default_scripts', function($scripts) {
if (!is_admin() && isset($scripts->registered['jquery'])) {
$scripts->registered['jquery']->deps = array_diff($scripts->registered['jquery']->deps, ['jquery-migrate']);
}
});
// Remove Global Styles and Gutenberg's block library styles
add_action('wp_enqueue_scripts', function() {
wp_dequeue_style('wp-block-library'); // Gutenberg block styles
wp_dequeue_style('global-styles'); // Global styles
});
// Disable Google Maps (dequeue any registered Google Maps script)
add_action('wp_enqueue_scripts', function() {
wp_deregister_script('google-maps');
});
}
add_action('init', 'optimize_non_display_features');
Ringkasan Fitur yang Dinonaktifkan:
- Disable Emojis: Menonaktifkan emoji di frontend dan admin.
- Disable Embeds: Menonaktifkan oEmbed dan pendaftaran API oEmbed.
- Remove Shortlink: Menghapus shortlink dari header.
- Remove RSS Feed Links: Menghapus link RSS Feed dari header.
- Disable Password Strength Meter: Menonaktifkan meter kekuatan kata sandi.
- Disable Comments: Menonaktifkan komentar pada posting dan halaman.
- Remove Comment URLs: Menghapus kolom URL di form komentar.
- Disable Self Pingbacks: Menonaktifkan pingbacks untuk URL internal.
- Disable XML-RPC: Menonaktifkan XML-RPC untuk keamanan.
- Hide WP Version: Menyembunyikan versi WordPress dari header.
- Remove wlwmanifest Link: Menghapus link wlwmanifest (Windows Live Writer).
- Remove RSD Link: Menghapus link RSD (Really Simple Discovery).
- Remove jQuery Migrate: Menghapus dependensi jQuery Migrate.
- Remove Global Styles: Menonaktifkan gaya global dan gaya blok Gutenberg.
- Disable Google Maps: Menonaktifkan skrip Google Maps (jika digunakan).
function optimize_wordpress_settings() {
// Disable REST API untuk pengguna yang tidak terautentikasi
add_filter('rest_authentication_errors', function($result) {
if (!is_user_logged_in()) {
return new WP_Error('rest_disabled', 'REST API is disabled for unauthenticated users.', array('status' => 403));
}
return $result;
});
// Disable Heartbeat API (untuk mengurangi penggunaan sumber daya server)
add_action('init', function() {
wp_deregister_script('heartbeat');
});
// Mengatur frekuensi Heartbeat API (setiap 60 detik)
add_filter('heartbeat_settings', function($settings) {
$settings['interval'] = 60; // Dalam detik (60 detik = 1 menit)
return $settings;
});
// Batasi Post Revisions (membatasi jumlah revisi per post menjadi 1)
if (!defined('WP_POST_REVISIONS')) {
define('WP_POST_REVISIONS', 1); // Batasi hanya menyimpan 1 revisi
}
// Mengatur Autosave Interval (setiap 1 menit)
if (!defined('AUTOSAVE_INTERVAL')) {
define('AUTOSAVE_INTERVAL', 60); // Dalam detik (60 detik = 1 menit)
}
}
add_action('init', 'optimize_wordpress_settings');
Apa yang masih ada?
- Disable REST API untuk pengguna yang tidak terautentikasi.
- Disable Heartbeat API untuk mengurangi penggunaan sumber daya.
- Atur frekuensi Heartbeat API menjadi 60 detik.
- Batasi jumlah revisi per post (hanya menyimpan 1 revisi).
- Atur interval autosave menjadi 1 menit.
Menonaktifkan Komentar Melalui functions.php
// Menonaktifkan komentar di seluruh situs
function disable_comments_all() {
// Hapus dukungan komentar dari semua post types
foreach (get_post_types() as $post_type) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
add_action('admin_init', 'disable_comments_all');
// Menghapus link komentar dari admin bar
function disable_comments_admin_bar() {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
}
add_action('init', 'disable_comments_admin_bar');