我试图从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\');
?>