allow editors to edit menus?

I would like to be able to grant my editors the power to change the menu, can this be done?

The appearance tab doesn’t appear to be an option at all, can I make it so?

Related posts

Leave a Reply

7 comments

  1. add this to your theme’s functions.php:

    // add editor the privilege to edit theme
    
    // get the the role object
    $role_object = get_role( 'editor' );
    
    // add $cap capability to this role object
    $role_object->add_cap( 'edit_theme_options' );
    

    Update (suggested in comments):

    You probably shouldn’t do this on every request, AFAIK this causes a db
    write. Better on admin_init and only if !$role_object->has_cap('edit_theme_options')

  2. EDIT: update for WP 4.9 & only hiding menu items for Editor

    If you want your users to be able to change the navigation menu, but not the other options under appearance: use this

    // Do this only once. Can go anywhere inside your functions.php file
    $role_object = get_role( 'editor' );
    $role_object->add_cap( 'edit_theme_options' );
    

    You can comment out this entire code after you have refreshed your admin panel, because the above code will make persistent changes to the database.

    You now have all the options under appearance visible to the editors. You can hide the other options like so:

    function hide_menu() {
    
        if (current_user_can('editor')) {
    
            remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
            remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu
            remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php' ); // hide the customizer submenu
            remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php&autofocus%5Bcontrol%5D=background_image' ); // hide the background submenu
    
    
            // these are theme-specific. Can have other names or simply not exist in your current theme.
            remove_submenu_page( 'themes.php', 'yiw_panel' );
            remove_submenu_page( 'themes.php', 'custom-header' );
            remove_submenu_page( 'themes.php', 'custom-background' );
        }
    }
    
    add_action('admin_head', 'hide_menu');
    

    The last 3 lines in the hide_menu() function are theme specific for my theme. You can find the second parameter by clicking on the submenu you want to hide, in the admin panel. Your URL will then be something like: example.com/wp-admin/themes.php?page=yiw_panel

    So, in this example, the second parameter for the remove_submenu_page() function will be yiw_panel

  3. In WordPress 3.8, this would be better code than the current accepted answer.

    /**
     * @var $roleObject WP_Role
     */
    $roleObject = get_role( 'editor' );
    if (!$roleObject->has_cap( 'edit_theme_options' ) ) {
        $roleObject->add_cap( 'edit_theme_options' );
    }
    
  4. instal plugin “User Role Editor” – Switch edit_theme_options ON – install plugin Adminimize – switch off “Widgets” and “Switch Theme” for Editors 😉

  5. It’s 2020, WordPress is now past V5.3 so i thought i would contribute an updated version in which the setting is saved only once in the database – upon theme activation, and removed when the theme is desactivated.

    function add_theme_caps(){
      global $pagenow;
      // gets the author role
      $role = get_role('editor');
    
      if ('themes.php' == $pagenow && isset($_GET['activated'])) { 
              // Test if theme is activated
              // Theme is activated
              // This only works, because it accesses the class instance.
              // would allow the editor to edit the theme options
              $role->add_cap('edit_theme_options');
      } else {
             // Theme is deactivated
             // Remove the capability when theme is deactivated
             $role->remove_cap('edit_theme_options');
      }
    }
    add_action( 'load-themes.php', 'add_theme_caps' );
    
    

    I also prefer to code in an OOP style so this is an OOP version:

    
    /**
     * YourClient Class
     *
     * @author   John Doe
     * @package  YourClient
     * @since    1.0
     */
    if (!defined('ABSPATH')) {
        exit;
    }
    if (!class_exists('YourClient')) {
        /**
         * The main YourClient class
         */
        class YourClient
        {
            /**
             * Setup class
             */
    
            public function __construct()
            {
                // Give more privileges on Theme Activation
                add_action('load-themes.php', array($this, 'add_theme_caps'));
            }
    
            function add_theme_caps()
            {
                global $pagenow;
    
                // gets the author role
                $role = get_role('editor');
    
                if ('themes.php' == $pagenow && isset($_GET['activated'])) { // Test if theme is activated
                    // Theme is activated
    
                    // This only works, because it accesses the class instance.
                    // would allow the author to edit others' posts for current theme only
                    $role->add_cap('edit_theme_options');
                } else {
                    // Theme is deactivated
                    // Remove the capability when theme is deactivated
                    $role->remove_cap('edit_theme_options');
                }
            }
        }
    }
    
    
  6. I´ve found, that your menu will work this way: instal plugin “User Role Editor” and there you can edit condition for editor role and other too. Switch edit_theme_options ON. But now: you will see “menu” -option under “themes”, “widgets”.
    For me: After click to “menu” (as editor) I´d not see filled options but empty. So I´d deactivate plugin “User Role Editor” and filled options for “menu” appears correctly. Note that deactivating plugin “User Role Editor” remains conditions for editor active! Good for me, maybe it will help you too