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 Answers
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]);
    }
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *