隐藏具有管理员角色的特定用户ID的管理菜单

时间:2017-11-25 作者:Md. Amanur Rahman

我试图从wordpress仪表板中隐藏具有管理员角色的特定用户id的几乎每个管理菜单。我想给该用户唯一的选项来编辑名为课程的特定自定义帖子类型和其他自定义帖子类型事件。

我使用的LMS wordpress主题来自themeforest by designthemes。我不知道为什么这个主题只是不给除了管理员以外的其他角色(如编辑、贡献者等)访问WP管理员的权限。所以我决定给那个特定的用户管理员角色,这样他就可以进入wordpress仪表板。那么我的计划就是为这个用户隐藏其他管理菜单。

我使用了名为User role editor pro的插件和其他免费插件。但似乎没有任何效果。然后我尝试了以下代码。但这段代码正在从其他管理员仪表板中删除这些管理菜单,我希望删除这些菜单,仅此用户id的用户id为279。非常感谢您的帮助。这是站点链接https://impactmarketingsystems.com/

<?php
function hide_menu(){
 global $current_user;
 $user_id = get_current_user_id();
 // echo "user:".$user_id;   // Use this to find your user id quickly

    if($user_id != \'279\'){

        // To remove the whole Appearance admin menu you would use;

        remove_menu_page( \'themes.php\' );

        // To remove the theme editor and theme options submenus from
        // the Appearance admin menu, as well as the main \'Themes\'
        // submenu you would use 

        remove_menu_page( \'index.php\' );
        remove_submenu_page( \'index.php\', \'update-core.php\' );

        remove_submenu_page( \'themes.php\', \'themes.php\' );
        remove_submenu_page( \'themes.php\', \'theme-editor.php\' );
        remove_submenu_page( \'themes.php\', \'theme_options\' );

        remove_menu_page( \'users.php\' );
        remove_submenu_page( \'users.php\', \'user-new.php\' );
        remove_submenu_page( \'users.php\', \'profile.php\' );

        remove_menu_page( \'upload.php\' );
        remove_submenu_page( \'upload.php\', \'media-new.php\' );
        remove_submenu_page( \'upload.php\', \'upload.php?page=wp-smush-bulk\' );

        remove_menu_page( \'admin.php?page=Wordfence\' );
        remove_submenu_page( \'admin.php?page=Wordfence\', \'media-new.php\' );


        remove_menu_page( \'edit.php?post_type=dt_teachers\' );
        remove_submenu_page( \'edit.php?post_type=dt_teachers\', \'post-new.php?post_type=dt_teachers\' );

        remove_menu_page( \'edit.php?post_type=dt_portfolios\' );
        remove_submenu_page( \'edit.php?post_type=dt_portfolios\', \'post-new.php?post_type=dt_portfolios\' );
        remove_submenu_page( \'edit-tags.php?taxonomy=portfolio_entries\', \'edit-tags.php?taxonomy=portfolio_entries&post_type=dt_portfolios\' );

        remove_menu_page( \'edit.php\' );
        remove_submenu_page( \'edit.php\', \'post-new.php\' );
        remove_submenu_page( \'edit.php\', \'edit-tags.php?taxonomy=category\' );
        remove_submenu_page( \'edit.php\', \'edit-tags.php?taxonomy=post_tag\' );


        // Remove Page menu Items
        remove_menu_page( \'edit.php?post_type=page\' );
        remove_submenu_page( \'edit.php?post_type=page\', \'post-new.php?post_type=page\' );


        // Remove Comments Menu

        remove_menu_page( \'edit-comments.php\' );

        //// Remove LMS Menu
        remove_menu_page( \'admin.php?page=parent\' );

         remove_menu_page( \'tools.php\' );                  //Tools
         remove_menu_page( \'options-general.php\' );        //Settings

          remove_menu_page( \'plugins.php\' );        //Plugins

          remove_menu_page( \'edit.php?post_type=product\' );





// Not working
// Remove WP Contacts Items  
        remove_menu_page( \'admin.php?page=shwcp_options\' );
        remove_submenu_page( \'admin.php?page=shwcp_options\', \'admin.php?page=shwcp_options&db=1\' );
        remove_submenu_page( \'admin.php?page=shwcp_options\', \'admin.php?page=shwcp_add_db\' );
        remove_submenu_page( \'admin.php?page=shwcp_options\', \'admin.php?page=shwcp_delete_db\' );    


        remove_menu_page( \'admin.php?page=upme-settings\' ); 

        remove_menu_page( \'admin.php?page=ultimate_affiliates_pro\' );     


    }
}




add_action(\'admin_head\', \'hide_menu\');

?>

1 个回复
最合适的回答,由SO网友:Kanon Chowdhury 整理而成

问题在于你的逻辑陈述。现在,您正在尝试删除用户id不是“279”的仪表板人员,这意味着只有用户id 279才能看到仪表板。您可以在if语句中尝试此操作

if(is_admin() && $user_id == \'279\'){ //your codes }

结束

相关推荐

Users redirected to old site

如果我以管理员身份登录,一切都很好。但是,如果我以用户身份登录,它会重定向到旧的测试站点(用于运行站点的开发服务器)。我已经检查了数据库中的siteurl和home值是否正确。我也在使用付费会员pro插件。我搜索了数据库,找到了740个旧URL的条目:(有人能建议在不破坏现场的情况下,最好的前进方式吗?谢谢