如何在定制器中更改“Site Identity”选项卡所需的功能

时间:2015-10-28 作者:ChrisPlaneta

我正在构建一个多站点,其中站点管理员没有“管理选项”功能。问题是,没有这个上限,他们无法在自定义程序中看到“站点标识”选项卡,在那里他们可以更改站点图标(favicon)以及站点名称。

是否有方法更改显示此选项卡和保存其内容所需的功能?如果没有,是否有方法显示与此选项卡中相同的字段,但显示在自定义程序的自定义选项卡中?

谢谢你,祝你今天愉快。

2 个回复
最合适的回答,由SO网友:Bryan Willis 整理而成

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:
外观>小部件
外观>菜单
外观>自定义(如果当前主题支持它们)
外观>背景
外观>标题


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 );

SO网友:Pavel S.

您可以删除title_tagline 从customizer中删除部分,并添加您自己的海关控制部分,这基本上是“Site Identity”部分的副本here.

您只需使用管理员拥有的功能更改此处指定的功能。

您可以在中查看如何使用WordPress自定义API管理器official doc.

相关推荐

Plugin capabilities

我创建了一个界面,允许用户执行一定数量的操作,每个操作都有相关的功能(包括访问该界面)。我想有一个基本的能力(这里是原始的?)如果用户想要执行所有其他操作,则需要具备:如果用户可以删除项目,则用户还必须能够访问该界面。有几个插件允许添加/删除功能:我想防止出现用户可以删除但无法访问界面的情况。我知道,由于帖子类型、元功能和map\\u meta\\u cap filter,我很难将其应用到我的插件中。我可以一直检查这两个选项,但权限层次结构最终会更加复杂(比如,3个级别-用户必须具有访问\\u界面、创建\