wordpress - 如何隐藏和禁用 Wordpress 管理菜单项
问题描述
我有两个 Wordpress 管理员帐户,但我需要为一个管理员隐藏某些管理员菜单项。我已经找到了如何做到这一点,但是如何禁用通过 url 直接访问页面?像这样的高级访问管理器
到目前为止我有..
function hide_menu() {
$user = wp_get_current_user();
if($user && isset($user->user_login) && 'admin2' == $user->user_login) {
remove_menu_page( 'plugins.php' ); //Plugins
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'users.php' ); //Users
}
}
add_action('admin_head', 'hide_menu');
解决方案
简单的解决方案: 您可以使用此插件: https ://wordpress.org/plugins/prevent-direct-access/
编码解决方案:
add_action('template_redirect', function() {
// ID of the page you want to restrict from
if (!is_page(2072)) {
return;
}
// Provide the link of admin dashboard, so that page should only
// accessible
// through admin dashboard
if (wp_get_referer() === 'https://example.com/wp-admin/') {
return;
}
// we are on restricted page
// visitor is trying to access directly
// so redirect to home
wp_redirect(get_home_url());
exit;
} );
推荐阅读
- python - stylegan2 - tensorflow.python.framework.errors_impl.InvalidArgumentError
- unity3d - 显示其他玩家的分数
- c - c中的char *何时以null结尾?
- php - 在管理控制器中上传 CSV 文件 - 自定义模块
- python - 从 AWS lambda 发送图像的 zipfile,收到错误无法编组响应:
不是 JSON 可序列化的 - flutter - 颤动的网络:不支持的操作:_Namespace
- java - 如何弄清楚编写 Java 客户端来使用声纳 API 我收到 401 错误
- docker - 运行 mkdir 文件夹,添加文件夹 / 。和 COPY 文件夹/ 。在 Dockerfile 中不起作用
- jasper-reports - Jasper Reports 6:字段之间的额外空间
- apache-kafka - 将事件从 kafka 广播到越来越多的连接的最佳方式是什么?