对于开放注册的WordPress站点,如果你不希望其他用户在插件管理页面查看和禁用站点必要的插件,除了使用 WordPress用户角色编辑插件:User Role Editor 来分配用户权限以外,你还可以将隐藏已启用的插件(插件依旧正常运行,只是在插件管理界面看不到罢了),将下面的代码添加到主题的 functions.php 文件即可:
add_filter( 'all_plugins', 'hide_plugins');
function hide_plugins($plugins)
{
// 隐藏 你好,多莉 插件
if(is_plugin_active('hello.php')) {
unset( $plugins['hello.php'] );
}
// 隐藏 post series插件
if(is_plugin_active('simple-post-series/series.php')) {
unset( $plugins['simple-post-series/series.php'] );
}
return $plugins;
} |
add_filter( 'all_plugins', 'hide_plugins');
function hide_plugins($plugins)
{
// 隐藏 你好,多莉 插件
if(is_plugin_active('hello.php')) {
unset( $plugins['hello.php'] );
}
// 隐藏 post series插件
if(is_plugin_active('simple-post-series/series.php')) {
unset( $plugins['simple-post-series/series.php'] );
}
return $plugins;
}
这个例子中,我们隐藏的是 你好,多莉 和 Simple Post Series 这两个插件, is_plugin_active() 和 unset() 里面填写的是插件的主文件目录,请根据自己的需求进行修改即可。
以上例子是对任何用户(包括网站管理员)都隐藏了已启用的插件,如果你需要排除某个用户,可以参考下面的另一种写法:
function filter_visible_plugins($plugins) {
//添加插件的相对于 /wp-content/plugins/ 的路径
$pluginsToHide = array(
'akismet/akismet.php',
'hidden-plugin/hidden-plugin.php',
'another-plugin/filename.php',
);
//在这个例子中,我们对所有用户<a href="https://www.wpdaxue.com/tag/%e9%9a%90%e8%97%8f%e6%8f%92%e4%bb%b6" title="查看与【隐藏插件】相关的文章" target="_blank" rel="noopener">隐藏插件</a>,除了用户 smith
$currentUser = wp_get_current_user();
$shouldHide = $currentUser->get('user_login') != 'smith';
if ( $shouldHide ) {
foreach($pluginsToHide as $pluginFile) {
unset($plugins[$pluginFile]);
}
}
return $plugins;
}
add_filter('all_plugins', 'filter_visible_plugins'); |
function filter_visible_plugins($plugins) {
//添加插件的相对于 /wp-content/plugins/ 的路径
$pluginsToHide = array(
'akismet/akismet.php',
'hidden-plugin/hidden-plugin.php',
'another-plugin/filename.php',
);
//在这个例子中,我们对所有用户<a href="https://www.wpdaxue.com/tag/%e9%9a%90%e8%97%8f%e6%8f%92%e4%bb%b6" title="查看与【隐藏插件】相关的文章" target="_blank" rel="noopener">隐藏插件</a>,除了用户 smith
$currentUser = wp_get_current_user();
$shouldHide = $currentUser->get('user_login') != 'smith';
if ( $shouldHide ) {
foreach($pluginsToHide as $pluginFile) {
unset($plugins[$pluginFile]);
}
}
return $plugins;
}
add_filter('all_plugins', 'filter_visible_plugins');
请根据自己的需要,修改第 3 行下面的插件主文件目录,以及 11 行的用户名
来源:
https://www.wpdaxue.com/hide-wordpress-activated-plugins.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32479.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57