我发现需要一个站点编辑器来编辑菜单。我找到了一些answers 这表明add_cap()
方法,添加edit_theme_options
编辑角色的能力。
这should be done once 然后从中删除functions.php
:
// Do this only once. Can go anywhere inside your functions.php file
$role_object = get_role( \'editor\' );
$role_object->add_cap( \'edit_theme_options\' );
相同的答案显示了隐藏不需要的外观子菜单的方法。但是它also hides those sub-menus to Administrator role.我的问题是:这是解决这个问题的正确方法吗?将子菜单显示给管理员,但将其隐藏给编辑器角色?
// Show Appearance sub-menus only to users with \'manage_options\' capability
function hide_menu() {
if ( ! current_user_can( \'manage_options\' ) ) {
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\', \'custom-header\' );
remove_submenu_page( \'themes.php\', \'custom-background\' );
}
}
add_action(\'admin_head\', \'hide_menu\');