【问题标题】:Hide specific dashboard items for user in Wordpress在 Wordpress 中为用户隐藏特定的仪表板项目
【发布时间】:2016-03-09 19:20:07
【问题描述】:

在我的网站仪表板中,我必须为一位具有管理员角色的用户隐藏媒体、评论、联系人菜单项。我在 Google 上搜索说我必须使用 remove_cap 函数,但找不到足够的信息来启动我的任务。

【问题讨论】:

    标签: wordpress dashboard


    【解决方案1】:

    你可以在你的functions.php中加入这样的东西。 :

    add_action( 'admin_menu', 'adjust_the_wp_menu', 999999 );
    function adjust_the_wp_menu() {
        $user = wp_get_current_user();
    
        if($user && isset($user->user_login) && 'desired_user_login' == $user->user_login)
        {
            //Remove menu items from admin area
            remove_menu_page( 'edit-comments.php' );//For comments
            remove_menu_page( 'upload.php' );//For media
            //Remove third party plugins admin menu items
            remove_menu_page( 'edit.php?post_type=your_custom_post_slug' );//for custom posts
            remove_menu_page( 'your_plugin_page_slug' );//for custom plugin's page
            // do stuff
        }
    }
    

    不确定 Wordpress 中的“联系人”菜单是什么。我猜它是由一些插件添加的。您可以尝试找出它的 slug 并在上面的代码中使用它。

    另外请注意,它只会隐藏菜单项。如果直接访问相应的 url,页面本身仍然可用。为了防止这种情况,您应该管理用户角色或将一些条件逻辑放入您的 functions.php。

    【讨论】:

    • 谢谢,这正是我想要的!
    猜你喜欢
    • 2013-12-17
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 2014-09-29
    • 2016-04-10
    相关资源
    最近更新 更多