WordPress:Add_cap ||仅编辑菜单

Wordpress : Add_cap || edit menu only

(首先,抱歉我的英语不好)

我想知道是否有一种纯粹的 php 方式允许 编辑器用户 编辑菜单。

此代码允许 editor 访问 appearance 菜单并且它工作正常。

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

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

但我不想让他编辑主题或小部件。我知道有插件可以管理这些功能,但我正在寻找一种简单的 php 方法来做到这一点,有什么想法吗?

提前致谢!

你怎么看这个?

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