自定义WordPress管理菜单:如何使编辑器可编辑

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

本文关键字:何使 编辑器 编辑 WordPress 管理 菜单 自定义      更新时间:2023-09-26

我在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' );

使用read,我可以让编辑器看到菜单,但是当他们试图更改设置时,WordPress告诉他们没有必要的权限。

有谁知道我怎样才能让编辑对设置进行编辑?

我认为正确的权限是能够改变它是edit_theme_options,所以尝试将它添加到您的functions.php:

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

然后,编辑器将看到外观下的所有选项。您可以隐藏其他选项,如下所示:

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');

如果你想让这些调整更容易,使用用户角色编辑器插件