The edit_theme_options
capability controls access to the widgets page but also to the menus page.
You can then remove the menus submenu from appearance for a specific role, and if someone tries to get there by url, redirect it :
/**
* Remove the "Menus" submenu from Appearance
*/
function remove_menus()
{
if (in_array('administrator', wp_get_current_user()->roles))
{
remove_submenu_page('themes.php', 'nav-menus.php');
}
}
add_action('admin_menu', 'remove_menus');
/**
* Redirect nav-menus.php to the dashboard
*/
function redirect_menus()
{
global $pagenow;
if ($pagenow === 'nav-menus.php' && in_array('administrator', wp_get_current_user()->roles))
{
wp_redirect(admin_url());
}
}
add_action('admin_init', 'redirect_menus');
Of course, replace the administrator
role by the one you want.