Allow access to WordPress Appearance menu items

How to allow access for selected role to the selected menu items of the WordPress Appearance menu? The most menu items under “Appearance” menu at WordPress administrator back-end use the same “edit_theme_options” user capability to check if current user has access to it (read more…). Thus if user has access to the “Widgets” menu, he has access to the rest menu items: “Themes”, “Customize”, “Menu”, “Header”, “Background”. What to do if you wish to allow some role(s) change “Widgets”, “Menus” but prohibit access to other “Appearance” menu items?
We can achieve this with additional PHP code, used as the must-use plugin. You may download it here. Create folder “wp-content/mu-plugins”, place there file from the zip archive you’ve downloaded.

Look how’s this code is configured:

/* 
 * Appearance permissions: edit Appearance menu for selected roles
 * Author: Vladimir Garagulya
 * email: [email protected]
 * 
 */
  
class AppearancePermissions {

    // roles to which allow the Appearance menu
    private $allowed_roles = array('editor');
    // allowed items from Appearance menu
    private $allowed_items = array(
        'widgets.php',
        'nav-menus.php'
    );
    // capabilities required by WordPress to access to the menu items above
    private $required_capabilities = array(
      'edit_theme_options'  
    );
    
    private $prohibited_items = array();
    
    

This configuration allows “Widgets” and “Menus” menu items from “Appearance” submenu for the users with role “Editor”. There is no need to add “edit_theme_options” capability to role “Editor”. It is added by plugin automatically.
User roles is configured at line #13. Just replace “editor” there to any role for which you wish to allow access, or add a new role to this array.
Allowed menu items are configured at line #15. The data was described at the this post, submenu “Appearance”, column “Script”.
Required capabilities are configured at line #20 and were taken from the column “Capability” of the post I referenced above.

So you see that changing plugin configuration you may setup custom restrictions to the WordPress “Appearance” menu.

If there are any other menu items (not under Appearance) secured with required capabilities automatically added, those menu items are blocked by this script automatically.

If you need the universal tool to block any selected menu item for given role, look at this add-on to User Role Editor Pro: “Block WordPress admin menu items.”

Share