-
作者帖子
-
要禁用此更新通知,设置菜单或管理仪表板中的任何其他位置都不会切换。为了防止 WordPress 在您的 WordPress 仪表板上显示这些信息片段,您需要将 PHP 代码片段添加 到您的 functions.php 文件中。
因此,请转到您主题的文件夹 (/ wp-content / themes / your-theme) 并打开 functions.php 文件。
现在通过该文件底部的以下代码:
禁用 WordPress 更新通知
// hide update notifications function remove_core_updates(){ global $wp_version;return(object) array('last_checked'=> time(),'version_checked'=> $wp_version,); } add_filter('pre_site_transient_update_core','remove_core_updates'); //hide updates for WordPress itself add_filter('pre_site_transient_update_plugins','remove_core_updates'); //hide updates for all plugins add_filter('pre_site_transient_update_themes','remove_core_updates'); //hide updates for all themes
如果您只想隐藏核心更新,主题更新或插件更新,请删除最后三行中的任何一行。
保存你的文件,并在你的 WordPress 管理区更新通知应该消失。如果您与客户合作,这可能是一个优雅的解决方案,让您尽可能简单地保持客户仪表板的界面。
「有一个新版本的 XYZ 插件可用」 。这个消息对 WordPress 管理员来说非常熟悉。但有时候,我们需要把它关掉。例如,我只是定制了一个插件,不想让我的定制代码被不知道这个插件的人覆盖。
WordPress 的,插件更新通知
实际上有多个解决方案。让我告诉你怎么做。
解决方案 1 – 更改版本号
没有太多的黑客,只需将插件的版本号更改为超大号码 (如 999.9) 就可以停止更新通知。因为 999 应该保持很长一段时间的最新版本。但是当我遇到来自客户端的 「禁用 WordPress 插件更新通知」 的请求时,我意识到我需要一个认真的解决方案,而不是用虚假的版本号欺骗。快速谷歌搜索显示另外两个选项。
解决方案 2 – http_request_args 钩子
// Disable plugin update check function my_prevent_update_check($r, $url) { if (0 === strpos($url,'https://api.wenpai.org/plugins/update-check/')){ $my_plugin = plugin_basename(__FILE__); $plugins = unserialize($r['body']['plugins']); unset($plugins->plugins[$my_plugin]); unset($plugins->active[array_search($my_plugin, $plugins->active )]); $r['body']['plugins'] = serialize($plugins); } return $r; } add_filter('http_request_args', 'my_prevent_update_check', 10, 2);
这个代码片段挂钩到 http_request_args 中,并从 http 请求中传递的查询参数中移除插件。因此,这段代码片段必须插入到我们要禁用更新检查的插件中。
如果有多个插件我们想禁用更新检查,我们需要插入这个片段到每个插件。并确保我们在不同的插件中使用不同的函数名称。 (即 my_prevent_update_check_nnn 而不是 my_prevent_update_check)
解决方案 3 – site_transient_update_plugins 挂钩
// Disable plugin update check function my_disable_filter_plugin_updates($value) { unset($value->response['plugin/plugin.php']); return $value; } add_filter('site_transient_update_plugins', 'my_disable_filter_plugin_updates');
这个解决方案更简单但更强大。要使用它,我们可以把它放到 function.php 或我们自己的插件 (我最喜欢的) 中。只要记住将第 3 行中的 「plugin / plugin.php」 替换为实际的插件路径和主 PHP 文件。例如:使用
Akismet 在/ akismet.php
将停止检查更新插件 Akismet 的 WordPress 。
要在更多插件上禁用更新检查,只需使用相同的 unset() 函数声明每个插件即可。例如:以下代码将停止对 Akismet&Events Manager 的更新检查。
// Disable plugin update check function my_disable_filter_plugin_updates($value) { unset($value->response['akismet/akismet.php']); unset($value->response['events-manager/events-manager.php']); return $value; } add_filter('site_transient_update_plugins', 'my_disable_filter_plugin_updates');
此回复已被标记为私有,🔒 仅楼主及管理员可见。 -
作者帖子
- 哎呀,回复话题必需登录。