如何让角色“编辑”来控制菜单?

时间:2017-01-29 作者:Mohamed Yasin

如何让“编辑器”角色控制菜单我找到的唯一代码是

$role_object = get_role( \'editor\' );
但我不能用它

1 个回复
最合适的回答,由SO网友:Arsalan Mithani 整理而成

将此添加到functions.php

// Allow editors to see Appearance menu
$role_object = get_role( \'editor\' );
$role_object->add_cap( \'edit_theme_options\' );
function hide_menu() {
 
    // Hide theme selection page
    remove_submenu_page( \'themes.php\', \'themes.php\' );
 
    // Hide widgets page
    remove_submenu_page( \'themes.php\', \'widgets.php\' );
 
    // Hide customize page
    global $submenu;
    unset($submenu[\'themes.php\'][6]);
 
}
 
add_action(\'admin_head\', \'hide_menu\');

Source