2017-08-03 77 views
0

(第一,对不起我的英文不好)WordPress的:Add_cap ||编辑菜单仅

我想知道如果有一个纯PHP的方式,让一个编辑器用户编辑菜单。

此代码允许编辑访问外观菜单,它工作正常。

// get the the role object 
$role_object = get_role('editor'); 

// add capability to this role object 
$role_object->add_cap('edit_theme_options'); 

但我不想让他编辑的主题或部件。我知道有插件来管理这些功能,但我正在寻找一个简单的PHP方式来做到这一点,任何想法?

在此先感谢!

回答

1

您对此有何看法?

$role_object = get_role('editor'); 
$role_object->add_cap('edit_theme_options'); 

add_action('admin_head', function() 
{ 
    // Check if the user === 'editor' 
    if (is_object(get_role('editor'))) { 
     remove_submenu_page('themes.php', 'themes.php'); 
     remove_submenu_page('themes.php', 'widgets.php'); 
    } 
}); 
+0

我不知道'remove_submenu_page'!确实帮助了很多人,这正是我所期待的,谢谢!我有点新的Wordpress :) –

+0

@AlexisWollseifen很高兴它现在工作!不要忘记设置你的问题来解决。 – justkidding96