2

So I found some handy snippets to help remove admin menu items. However, I'm having trouble with the sub menu items. I want to keep the appearance menu, but get rid of the Themes, Widgets, and Editor.

function remove_menus()
{
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login == 'username')
{
    $restricted = array(__('Posts'),
                        __('Links'),                     
                        __('Comments'),
                        __('Plugins'),
                        __('Users'),
                        __('Tools'),    
                        __('Settings')

    );
    end ($menu);
    while (prev($menu)){
        $value = explode(' ',$menu[key($menu)][0]);
        if(in_array($value[0] != NULL?$value[0]:"" , $restricted))
       {unset($menu[key($menu)]);}
    }// end while
    }// end if
    }
    add_action('admin_menu', 'remove_menus');

function remove_submenus()
{
global $menu;
global $current_user;
get_currentuserinfo();
if($current_user->user_login == 'username')
{
    global $submenu;
    unset($submenu['themes.php'][10]); // remove the theme editor
}
}
add_action('admin_menu', 'remove_menus');
2

Try this:

add_action('_admin_menu', 'remove_editor_submenu', 1);
function remove_editor_submenu() {
    remove_action('admin_menu', '_add_themes_utility_last', 101);
}

add_action('admin_init', 'remove_theme_submenus');
function remove_theme_submenus() {
    global $submenu; 
    unset($submenu['themes.php'][5]);
    unset($submenu['themes.php'][7]);
    unset($submenu['themes.php'][15]);
}

To disable other submenu names, go to ./wp-admin/menu.php and search for the item(s) you want to disable.

EDIT: As far as disabling by username, I would instead add a new capability to a role and use that as your removal condition see here. Otherwise, just use what you already were using, like so:

add_action('_admin_menu', 'remove_editor_submenu', 1);
function remove_editor_submenu() {
    global $current_user;
    get_currentuserinfo();
    if($current_user->user_login == 'username') {
        remove_action('admin_menu', '_add_themes_utility_last', 101);
    }
}

add_action('admin_init', 'remove_theme_submenus');
function remove_theme_submenus() {
    global $submenu, $current_user;
    get_currentuserinfo();
    if($current_user->user_login == 'username') {
        unset($submenu['themes.php'][5]);
        unset($submenu['themes.php'][7]);
        unset($submenu['themes.php'][15]);
    }
}
| improve this answer | |
  • FYI: If the themes submenu is disabled, the Appearance top-level menu simply becomes a mirror of the next available submenu. So with all the submenus except for "Menus" disabled, "Appearance" now becomes the same as the "Menus" submenu. – Paul Oct 16 '11 at 23:18
  • NICE! It worked like a charm. How do I make it so it only effects the user I name like in the snippet where I took out several menus. Sorry for so many questions, thx for the help. – Alex Oct 17 '11 at 1:47
  • Look here to find out how to add a new capability to a role and use that as your removal condition. – Paul Oct 17 '11 at 7:02
  • And here is a more in-depth explanation of the method @Milo explained using remove_menu_page() and remove_submenu_page(): http://sethstevenson.net/customize-the-wordpress-admin-menu-based-on-user-roles/ – Paul Oct 17 '11 at 11:06
  • Wow, I can't believe I didn't know about this site till now. Thanks guys. I will read up on how to do everything. Thanks again for all the answers and code. – Alex Oct 17 '11 at 20:52
2

There are much simpler functions for removing menu and submenu pages since 3.1:

remove_menu_page() and remove_submenu_page()

however, the issue with removing themes is that the appearance menu IS the themes page.

EDIT- what you can do is remove the entire appearance menu, then create a new top level menu item using add_menu_page()

function wpse31255_add_menu_page(){
    add_menu_page( __('Nav Menus', 'mav-menus'), __('Nav Menus', 'nav-menus'), 'edit_themes', 'nav-menus.php', '', 99 );
}
add_action('admin_menu', 'wpse31255_add_menu_page');
| improve this answer | |
  • I added it to my functions.php and it is not working. Thanks for the tip about the remove_menu_page() and remove_submenu_page() functions. On the first code snippet I tried it with __('Appearance'), and without it. – Alex Oct 16 '11 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.