Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overrides remove_menu_page #37

Open
blogmom opened this issue Oct 9, 2016 · 1 comment
Open

Overrides remove_menu_page #37

blogmom opened this issue Oct 9, 2016 · 1 comment
Labels
Milestone

Comments

@blogmom
Copy link

blogmom commented Oct 9, 2016

With 2.0.0.-alpha: In my functions.php, I check if a user is an admin, and if not, then I hide all Admin Panel items using remove_menu_page. However, when AMM is activated, certain items reappear: Home, All Posts, All Comments, Available Tools. This is consistent and repeatable. When AMM plugin is deactivated, the items are again hidden. Here is my code, pop it into your functions.php and you'll see what I mean. With that code in your functions.php:

  1. deactivate AMM plugin and login as a non-admin user, navigate to wp-admin and notice the panel is empty.
  2. activate AMM plugin and refresh, notice the admin panel is no longer empty.
add_action('admin_menu', 'remove_admin_sidebar_from_endusers'); 
function remove_admin_sidebar_from_endusers ()  { 
    get_currentuserinfo();
    global $user_level;
    if ( $user_level <= 8 ) {
        remove_menu_page( 'index.php' );                  //Dashboard
        remove_menu_page( 'profile.php' );                //Profile     
        remove_menu_page( 'jetpack' );                    //Jetpack* 
        remove_menu_page( 'edit.php' );                   //Posts
        remove_menu_page( 'upload.php' );                 //Media
        remove_menu_page( 'edit.php?post_type=page' );    //Pages
        remove_menu_page( 'edit-comments.php' );          //Comments
        remove_menu_page( 'themes.php' );                 //Appearance
        remove_menu_page( 'plugins.php' );                //Plugins
        remove_menu_page( 'users.php' );                  //Users
        remove_menu_page( 'tools.php' );                  //Tools
        remove_menu_page( 'options-general.php' );        //Settings
        //echo "<script type='text/javascript' >document.body.className+=' folded';</script>";  //collapse by default
        remove_meta_box('dashboard_right_now', 'dashboard', 'core');
        remove_meta_box('dashboard_activity', 'dashboard', 'core');
        remove_meta_box('dashboard_recent_comments', 'dashboard', 'core');
        remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
        remove_meta_box('dashboard_plugins', 'dashboard', 'core');
        remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
        remove_meta_box('dashboard_recent_drafts', 'dashboard', 'core');
        remove_meta_box('dashboard_primary', 'dashboard', 'core');
        remove_meta_box('dashboard_secondary', 'dashboard', 'core');        
    } 
} 
@swissspidy swissspidy added the bug label Oct 9, 2016
@swissspidy
Copy link
Collaborator

Interesting, thanks for your report!

Right now the plugin hooks into admin_menu as well and basically tries to build a new menu from scratch. Since the complete menu is stored in an option, the removed pages are still in there and need to be removed somehow.

I suspect that Parent_Menu_Iterator::is_top_level_item() correctly returns false because the menu pages do not exist anymore. However, Parent_Menu_Iterator::is_submenu_item() might return true in that case because every parent menu item has a child with the same name.

Parent_Menu_Iterator::is_submenu_item() exists because you're able to move a child menu item to the top level and this needs to be detected somehow. Perhaps this detection needs to be done better so that we can distinguish between moved and deleted menu items.

@swissspidy swissspidy added this to the 2.0.0 milestone Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants