1

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

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

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".

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.