本文最后更新于 117 天前,其中的信息可能已经过时,如有错误请发送邮件到 admin@yunsen2025.top
总体思路:WP 访问后台时会请求更新和很多杂七杂八的 api,这些服务的服务器都在国外,这些功能在大陆一点作用也没有(用它官方的还不如你装个文派叶子),禁用掉可以极大提升站点速度
很多插件的禁用功能禁用的不彻底(文派叶子也是)用这两段代码可以完全禁用,并且不会对功能产生影响
第一段(加到主题的 function.php 中)
// Turn off updates completely add_filter('automatic_updater_disabled', '__return_true'); // Disable the WordPress core auto update add_filter('pre_site_transient_update_core', '__return_null'); add_filter('pre_site_transient_update_plugins', '__return_null'); add_filter('pre_site_transient_update_themes', '__return_null'); // disable sending alert updates email add_filter( 'auto_core_update_send_email', '__return_false' ); // disable auto upadte translation add_filter( 'auto_update_translation', '__return_false' ); // remove auto check wp/theme/plugins update remove_action('init', 'wp_schedule_update_checks'); wp_clear_scheduled_hook('wp_version_check'); wp_clear_scheduled_hook('wp_update_plugins'); wp_clear_scheduled_hook('wp_update_themes'); // remove the timed checking for upadtes task remove_action('admin_init', '_maybe_update_core'); remove_action('admin_init', '_maybe_update_plugins'); remove_action('admin_init', '_maybe_update_themes');
这个代码片段会有效地禁用 WordPress 中的各种自动更新,包括核心更新、主题和插件更新、翻译更新以及相关的电子邮件提醒。它还会移除定期检查更新的计划任务。
(代码解释来自 GPT4o)
这会禁用 wp 的自动更新和定期检查,避免时不时请求在国外的服务器进行更新,极大提高了后台速度
如果要更新手动去后台 “更新” 那一栏手动更新就好,也更自由
第二段(加到站点根目录中的 wp-config.php 中)
/*Disable the external connection*/ define('WP_HTTP_BLOCK_EXTERNAL', true); /*allow the localhost connection*/ define('WP_ACCESSIBLE_HOSTS', 'localhost'); // Disable auto update define( 'WP_AUTO_UPDATE_CORE', false ); // Disable auto insatll theme or plugins define('DISALLOW_FILE_MODS', true); //(注意!!这一条会禁用wp后台的文件主题编辑器)
这段代码禁用全部 wp 对外部的 HTTP 链接(防止请求 api)第二行放行了 localhost 本地的连接(外部数据库慎用)
三四行分别禁用了内核和插件的定期检查与自动更新
博主有点东西