We’re setting up WordPress as a CMS, as such we’d like to completely hide the Posts tab from the admin menu. Using a plugin, we have created several roles and assigned different capabilities.
We’d like to have some roles that are able to edit site menus. Giving them the edit_theme_options capability allows them to get to the menu screen. Once there they can edit, delete menu items, and even create new menus, but unless I also give them the edit_posts capability, they are unable to add new menu items. They can add a menu item by clicking on “Add to menu”, but after they click on “Save menu”, the item disappears and no users can see it.
We’ve looked around for some solutions and the best thing we’ve found was to try reassigning the capabilities by changing the $wp_post_types[‘nav_menu_item’]->cap object, but that doesn’t seem to have any effect.
Looking into the database, I noticed that when a user without edit_posts adds a menu item, it’s being added to the wp_posts table, but there’s no corresponding row in the wp_terms_relationships table.
Without digging more into the WordPress code, we’re kind of stuck at this point. So is there a way to allow users to add menu items to a menu without giving them the edit_posts capability?
I was originally thinking that the issue was that something was wrong with the capability for nav_menu_item post type. My eureka moment came after digging through the WordPress code and discovering that taxonomies have capabilities as well.
So the our solution was to change the capability needed:
$wp_taxonomies['nav_menu']->cap->assign_terms = 'edit_theme_options';
Viewing 1 replies (of 1 total)
The topic ‘Users can't add menu items without the edit_posts capability’ is closed to new replies.