douzai8285
2018-05-12 05:19 阅读 92
已采纳

除超级管理员外,WordPress删除菜单页面

I have written a snippet to remove some WordPress menu pages.

add_action( 'admin_menu', 'notadmin_remove_menus', 999 ); 
function notadmin_remove_menus() {
    remove_menu_page('edit.php');
    remove_menu_page('edit.php?post_type=page');
    remove_menu_page('upload.php');
    remove_menu_page('jetpack');
    remove_menu_page('users.php');
    remove_menu_page('tools.php');
    remove_menu_page('edit-comments.php');
    remove_menu_page('edit.php?post_type=featured_item');
    remove_menu_page('edit.php?post_type=feedback');
    remove_menu_page('edit.php?post_type=blocks');
}

The problem is this code also remove menu pages for super admin. I want to remove these menu for all users except super admin. Please help.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douan3414 douan3414 2018-05-12 05:49

    Try this code

    add_action( 'admin_menu', 'notadmin_remove_menus', 999 ); 
    function notadmin_remove_menus() {
        if ( !is_super_admin() ) {
            remove_menu_page('edit.php');
            remove_menu_page('edit.php?post_type=page');
            remove_menu_page('upload.php');
            remove_menu_page('jetpack');
            remove_menu_page('users.php');
            remove_menu_page('tools.php');
            remove_menu_page('edit-comments.php');
            remove_menu_page('edit.php?post_type=featured_item');
            remove_menu_page('edit.php?post_type=feedback');
            remove_menu_page('edit.php?post_type=blocks');
        }
    }
    

    or

    if ( !is_super_admin() ) {
        add_action( 'admin_menu', 'notadmin_remove_menus', 999 ); 
    }
    
    
    function notadmin_remove_menus() {
    
        remove_menu_page('edit.php');
        remove_menu_page('edit.php?post_type=page');
        remove_menu_page('upload.php');
        remove_menu_page('jetpack');
        remove_menu_page('users.php');
        remove_menu_page('tools.php');
        remove_menu_page('edit-comments.php');
        remove_menu_page('edit.php?post_type=featured_item');
        remove_menu_page('edit.php?post_type=feedback');
        remove_menu_page('edit.php?post_type=blocks');
    
    }
    
    点赞 评论 复制链接分享

相关推荐