• Hello,

    I know only the administrator role has access to the Appearance menus – themes, customize, widgets, menus, etc. – by default.

    I am trying to implement a code to allow the role “editor” to don’t have access to themes, customize, widgets and theme-editor, but only have access to the menus page. Following code added to

    functions.php

    is working fine… please suggest update.

    Note that users who know the correct path to the hidden options also can’t access except menu.

    // Allow editors to see access the Menus page under Appearance but hide and restrict other options
    function access_control_4_editor() {
     	$user = wp_get_current_user();
    	// Check if the current user is an Editor
    	if ( in_array( 'editor', (array) $user->roles ) ) {
    		//Array variable for access restriction rights
    		$access_capabilities = array(
    			'themes.php',
    			'customize.php',
    			'widgets.php',
    			'theme-editor.php',
    			'edit-comments.php'
    		);
    
    		//Restrict access to page from URL
    		global $pagenow;
    		if ( in_array($pagenow, $access_capabilities)) {
    			if ( function_exists('admin_url') ) {
    				wp_redirect( admin_url('#') );
    			}
    		}
    		// Hide the links in menu
    		foreach ( $access_capabilities as $access_capability_link ) {
    			remove_submenu_page( 'themes.php', $access_capability_link );
    		}
    
    		// Remove Customize from the Appearance submenu
    		global $submenu;
    	    unset($submenu['themes.php'][6]);
    	}
    }
    add_action('admin_menu', 'access_control_4_editor', 10);
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘restrict editors to access themes, customize, widgets’ is closed to new replies.