Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I found an answered question here Remove menus and submenus 2 Answers for my problem but is there a way of changing the code a bit so that it removed the submenus for all Editor roles. not only for one user? and is there a way of improving this code? I am using 3.5.1 version of wordpress

code that I am using:

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]);
    }
}
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Replace all occurrences of $current_user->user_login == 'username' with in_array('editor', $current_user->roles). And you can remove the call to get_currentuserinfo(); as for the user information is available from the global variable $current_user.

Here's a code swap:

add_action('_admin_menu', 'remove_editor_submenu', 1);
function remove_editor_submenu() {
    global $current_user;
    if(in_array('editor', $current_user->roles)) {
        remove_action('admin_menu', '_add_themes_utility_last', 101);
    }
}

add_action('admin_init', 'remove_theme_submenus');
function remove_theme_submenus() {
    global $submenu, $current_user;
    if(in_array('editor', $current_user->roles)) {
        unset($submenu['themes.php'][5]);
        unset($submenu['themes.php'][7]);
        unset($submenu['themes.php'][15]);
    }
}
share|improve this answer
1  
Thanks! this did the job! :) –  Pullapooh Feb 20 '13 at 15:59
add comment

Use user_can.

if (user_can($current_user->ID,'editor')) { ...

I don't know which of the two functions you want that in but is should be simple to replace or add to your existing if conditional.

You say "Editor roles"-- plural-- but I am assuming you mean "all users who are in the Editor role".

share|improve this answer
    
I will check it out :) thanks for the suggestion –  Pullapooh Feb 20 '13 at 16:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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