我想让编辑器角色有权编辑提要栏及其内容。我有一个文本小部件在那里,为了编辑这个文本小部件,用户需要是管理员-这太糟糕了。如何授予编辑器角色权限,使其能够编辑侧边栏?
Give Editor Access To Sidebar
2 个回复
最合适的回答,由SO网友:Elliott 整理而成
这个edit_theme_options
该功能应允许用户编辑本页所述的侧栏:http://codex.wordpress.org/Appearance_Widgets_SubPanel
要添加到的代码functions.php
$role = get_role(\'editor\');
$role->add_cap(\'edit_theme_options\');
Edit:
这可以防止编辑器访问主题或菜单function custom_admin_menu() {
$user = new WP_User(get_current_user_id());
if (!empty( $user->roles) && is_array($user->roles)) {
foreach ($user->roles as $role)
$role = $role;
}
if($role == "editor") {
remove_submenu_page( \'themes.php\', \'themes.php\' );
remove_submenu_page( \'themes.php\', \'nav-menus.php\' );
}
}
add_action(\'admin_menu\', \'custom_admin_menu\');
我还没有机会对此进行测试,但它只会将它们从菜单中删除,它们可能仍然可以通过直接键入URL来访问它们。SO网友:eddiemoya
如果您只是想尽可能简单地配置此功能,请使用Members插件。您需要添加的功能是“edit\\u theme\\u options”。请注意,这将不仅仅授予widgets区域,还授予编辑器访问整个外观菜单的权限。See here
http://wordpress.org/extend/plugins/members/
如果要以编程方式执行此操作,则需要使用add\\u cap()。$editor = get_role(\'editor\');
$editor->add_cap(\'edit_theme_options\');
您可以将该代码放入它自己的插件中,然后您就完成了。或者把它放进functions.php.结束