• I know there have been many discussion on hiding submenus based on role, but I cannot seem to get it to work in a way that hides submenus for the editor role in my multisite but not for other roles.

    I am trying to hide:

    Appearance > Themes
    Appearance > Customize
    Appearance > Header
    Appearance > Background

    I only want editors to have access to Widgets and Menus. I thought the below would work but it hasn’t:

    $role = get_role( 'editor' );
    }
    
    function my_remove_menu_pages() {
    	if(!current_user_can('editor')) {
    		remove_submenu_page ('themes.php', 'themes.php');
    	        remove_submenu_page ('themes.php', 'custom-header');
                    remove_submenu_page( 'themes.php', 'custom-background');
    	}
    }
    add_action( 'admin_init', 'my_remove_menu_pages' );

    I appreciate any help.

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter moose123

    (@moose123)

    I was able to solve this. I’m sure there’s a MUCH more elegant way to do it, but this is what I did to hide all but “Menus” and “Widgets” from both the fly-out menu and from the top-level menu. After adding a new role and a new capability to that role, I keyed off that new capability to filter out the menus:

    // remove some menus and sub-menus for editor
    $cap = 'no_see_menus';
    function edit_admin_menus() {
        global $submenu;
    		if(!current_user_can($cap)){
    			remove_menu_page('tools.php');
    	    remove_submenu_page('themes.php','themes.php');
    			remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2F' );
    			remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Findex.php' );
    			remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Fwidgets.php');
    			remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Fpost-new.php%3Fpost_type%3Dpage');
    			remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Fnav-menus.php');
    			}
    }
    add_action( 'admin_menu', 'edit_admin_menus' );
    
    // remove custom backgound and custom header menus and sub-menus for editor
    $cap = 'no_see_menus';
    function remove_twentyeleven_options(){
    		if(!current_user_can($cap)){
    				remove_custom_background();
    				remove_custom_image_header();
    			}
    }
    add_action( 'after_setup_theme','remove_twentyeleven_options', 100 );
Viewing 1 replies (of 1 total)
  • The topic ‘Hide submenus based on role’ is closed to new replies.