1

I'm building a multisite in which site admins have no "manage options" capability. The problem is that withut this cap they cannot see the "site identity" tab in the customizer, where they can change the site icon (favicon) as well as the site's name.

Is there a way to change the required capability to show this tab and save its contents? If not, is there a way to display the same fields as in this tab but in a custom tab in the customizer?

Thank you and have a nice day.

3
  • if the admin is not admining, then who will admin the site, and why can't he do the favicon as well? Commented Oct 28, 2015 at 17:47
  • The idea is to have as many options pre-set up for non technical users. Thus options will be hidden leaving individual site admins only with content editing and visual tweaks. Commented Oct 30, 2015 at 12:18
  • So once it is pre set even god can not change it? If you don't want the admin to be able to do X, then just remove the GUI for it. Trying to elavate an editor into an admin seems to be the wrong way to go about it. Editors should edit content not set favicons.... You might end up making editors a de-facto admins, one small feature at a time. Commented Oct 30, 2015 at 12:51

2 Answers 2

3

This is how I've interpreted from the wordpress docs at least. Originally these settings were made with add_setting and it is where the capability was originally set. Fortunately, we can use get_setting to change that value. It seems to work very well for your case.

function wpseo_206907_add_back_customizer_controls_for_not_admins( $wp_customize ) {
    $wp_customize->get_setting( 'blogname' )->capability = 'edit_theme_options'; // or edit_posts or whatever capability your site owner has
}
add_action( 'customize_register', 'wpseo_206907_add_back_customizer_controls_for_not_admins', 1000 );



If for some reason they don't have access to the customizer you need to give them the edit_theme_options capability first.

function wpseo_206951_add_capability_for_non_admin() {
    $roleObject = get_role( 'editor' ); // whoever should have access to theme changes
    if (!$roleObject->has_cap( 'edit_theme_options' ) ) {
        $roleObject->add_cap( 'edit_theme_options' );
    }
}
add_action( 'admin_init', 'wpseo_206951_add_capability_for_non_admin');


This will give them access to the following:
Appearance > Widgets
Appearance > Menus
Appearance > Customize if they are supported by the current theme
Appearance > Background
Appearance > Header


If you'd rather hide these pages all together do this:

function wpseo_206907_remove_by_caps_admin_menu() {
    if ( !current_user_can('manage_options') ) {
            remove_menu_page('themes.php'); // Appearance Menu on Admin
            remove_submenu_page( 'themes.php', 'widgets.php' );
            remove_submenu_page( 'themes.php', 'nav-menus.php' );
            remove_submenu_page( 'themes.php', 'theme-editor.php' );
    }
}
add_action('admin_menu', 'wpseo_206907_remove_by_caps_admin_menu', 999);


However, if you want them to have access to certain pages like widgets and menus, but not themes then do this instead:

add_action( 'admin_init', 'wpseo_206907_lock_theme' );  
function wpseo_206907_lock_theme() {
    global $submenu, $userdata;
    get_currentuserinfo();

    if ( $userdata->ID != 1 ) { 
        unset( $submenu['themes.php'][5] );
        unset( $submenu['themes.php'][15] );
    }
}


You'd also want to do this then to remove the theme change section section from the customizer:

function wpseo_206951_remove_customizer_controls_all( $wp_customize ) { 
   if ( !current_user_can('manage_options') ) {

   $wp_customize->remove_section("themes"); // Removes Themes section from backend

   // To remove other sections, panels, controls look in html source code in chrome dev tools or firefox or whatever and it will tell you the id and whether it's a section or panel or control. 
   //Example below (uncomment to use)

   // $wp_customize->remove_section("title_tagline");
   // $wp_customize->remove_panel("nav_menus");
   // $wp_customize->remove_panel("widgets");
   // $wp_customize->remove_section("static_front_page");

   }
}
add_action( 'customize_register', 'wpseo_206951_remove_customizer_controls_all', 999 );
0
0

You can remove the title_tagline section from the customizer and add your own section with customs control, which are basicly a copy of "Site Identity" piece here.

You will only have to change the capability specified there with one that your administrators have.

You can check out how to use WordPress Customize API Manager in the official doc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.