简体   繁体   English

自定义WordPress管理菜单:如何使其对编辑者可编辑?

[英]Custom WordPress admin menu: How to make it editable for editors?

I have added a custom menu to the sidebar in the admin panel in WordPress: 我在WordPress管理面板的侧栏中添加了自定义菜单:

function custom_settings_add_menu() {
  add_menu_page( 'custom_settings', 'Custom Settings', 'read', 'custom_settings', 'custom_settings_page', null, 20);
}
add_action( 'admin_menu', 'custom_settings_add_menu' );

With read , I could make the menu visible for editors, but when they try to change the settings, WordPress tells them that they don't have the necessary permissions. 使用read ,我可以使菜单对编辑者可见,但是当他们尝试更改设置时,WordPress告诉他们他们没有必要的权限。

Does anybody know how I can let editors make edits to the settings? 有人知道我如何允许编辑者对设置进行编辑吗?

I think the correct permission to be able to change it is edit_theme_options, so try adding it to your functions.php: 我认为能够更改它的正确权限是edit_theme_options,因此请尝试将其添加到您的functions.php中:

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

You will then have all the options under appearance visible to the editors. 然后,您将看到编辑器可见的所有选项。 You can hide the other options like so: 您可以像这样隐藏其他选项:

function hide_menu() {

    remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
    remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu
  //etc...

add_action('admin_head', 'hide_menu');

If you want to make life easier for these kind of adjustments, use the User Role Editor Plugin . 如果您想通过这些调整使生活更轻松,请使用“ 用户角色编辑器插件”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM