Hide custom menu items based on user roles
This plugin lets you hide custom menu items based on user roles. So if you have a link in the menu that you only want to show to logged in users, certain types of users, or even only to logged out users, this plugin is for you.
Nav Menu Roles is very flexible. In addition to standard user roles, you can customize the functionality by adding your own check boxes with custom labels using the nav_menu_roles
filter and then using the nav_menu_roles_item_visibility
filter to check against whatever criteria you need. You can check against any user meta values (like capabilities) and any custom attributes added by other plugins.
IMPORTANT NOTE
In WordPress menu items and pages are completely separate entities. Nav Menu Roles does not restrict access to content. Nav Menu Roles is only for showing/hiding nav menu items. If you wish to restrict content then you need to also be using a membership plugin.
Usage
- Go to Appearance > Menus
- Set the “Display Mode” to either “logged in users”, “logged out users”, or “everyone”. “Everyone” is the default.
- If you wish to customize by role, set the “Display Mode” to “Logged In Users” and under “Restrict menu item to a minimum role” check the boxes next to the desired roles. Keep in mind that the role doesn’t limit the item strictly to that role, but to everyone who has that role’s capability. For example: an item set to “Subscriber” will be visible by Subscribers and by admins. Think of this more as a minimum role required to see an item.
Support
Support is handled in the WordPress forums. Please note that support is limited and does not cover any custom implementation of the plugin. Before posting, please read the FAQ. Also, please verify the problem with other plugins disabled and while using a default theme.
Please report any bugs, errors, warnings, code problems to Github
Screenshots
Show the new options for the menu items in the admin menu customizer
FAQ
ChangeLog
2.1.2
2.1.1
- Fix: Top-level display of hidden child menu items of hidden parent menu items.
2.1.0
- New: Add support for “hiding” a menu item by role.
2.0.2
- Fix: PHP Fatal error: Uncaught Error: Call to undefined method WP_Customize_Manager::settings_previewed(). settings_previewed() does not exist until WordPress 3.9.0+.
2.0.1
- Tweak: Alphabetically sort role names.
2.0.0
- New: Customizer support! props @westonruter!
1.10.2
- Fix: Strict array typecasting for nav menu classes.
1.10.1
- Fix: Only auto-apply classes on front-end. Prevents appending duplicate classes on each save.
1.10.0
- Fix: My hook made it into core for WP5.4!! Can finally stop overriding the admin menu Walker.
1.9.5
- Fix: PHP Notice: Undefined variable $item
1.9.4
- Add the NMR roles as css classes to the menu output
- Improve menu editor role checkbox list UX, by making list items full-width. Props @lkraav
1.9.3
- Check all object properties exist before accessing. Resolves PHP notices for custom menu items.
1.9.2
- Include a !empty() check on menu $items
- Update donation link
1.9.1
- Update donation link
- Update required and tested against versions
1.9.0
- Add support for multisite. Props @open-dsi and @fiech.
1.8.5
1.8.4
- Prevent nav menu items edited in the customizer from rendering when they should be excluded
1.8.3
- Remove deprecated screen_icon()
1.8.2
- Reduce number of parameters passed to
add_action_links
filter
1.8.1
- Switch input names to use a counter [nav-menu-role][100][1]. For some reason [nav-menu-role][100][] doesn’t post an array and hypenated names [nav-menu-role][100][gold-plan] wreak havoc on the save routine. Shouldn’t impact anyone not using hyphenated role names.
1.8.0
- Fix style issue in WordPress 4.5
1.7.9
- revert priority of walker back to default because themes are not actually using the hook to add their own fields. sadface.
1.7.8
1.7.7
1.7.6
- tweak CSS to initially hide checkboxes on newly added menu items (defaults to “Everyone” so roles should not appear)
1.7.5
- Update Walker_Nav_Menu_Edit_Roles to mimic Walker_Nav_Menu in WordPress 4.4
1.7.4
- Change language in metabox to try to explain min caps versus strict role checking
- keep tweaking the FAQ
1.7.3
- update readme, update error notice, add more links to the FAQ
1.7.2
- add Italian language. props @sododesign
1.7.1
- Updated FAQ with patch instructions for conflicting plugins/themes
- add Portugeuse language. props @brunobarros
1.7.0
- adjust admin UI to be more user-friendly. Options are now: show to everyone, show to logged out users, and show to logged in users (optionally, logged in users by specific role)
1.6.5
- add Guajarati language. props @rohilmistry93
1.6.4
- more language issues -> sync svn+git version numbers
1.6.3
- Try again to add languages. Where’d they all go?
1.6.2
- Add French translation. Props @Philippe Gilles
1.6.1
- Update list of conflits
- Don’t display radio buttons if no roles – allows for granular permissions control
1.6.0
- Feature: Hiding a parent menu item will automatically hide all its children
- Feature: Add compatibility with Menu Item Visibility Control plugin and any plugin/theme that is willing to add its inputs via the
wp_nav_menu_item_custom_fields
hook. See the FAQ to make our plugins compatible.
1.5.1
- Hopefully fix missing nav-menu-roles.min.js SVN issue
1.5.0
- Switch to instance of plugin
- Add notice when conflicting plugins are detected
- Remove some extraneous parameters
- Add Spanish translation thanks to @deskarrada
1.4.1
- update to WP 3.8 version of Walker_Nav_Menu_Edit (prolly not any different from 3.7.1)
- minor CSS adjustment to admin menu items
- checked against WP 3.8
1.4
- Add to FAQ
- add JS flair to admin menu items
- update to WP 3.7.1 version of Walker_Nav_Menu_Edit
1.3.5
- Add nav_menu_roles_item_visibility filter to work with plugins that don’t use traditional roles
1.3.4
- Update admin language thanks to @hassanhamm
- Add Arabic translation thanks to @hassanhamm
1.3.3
- Fix Nav_Menu_Roles_Import not found error
1.3.2
- Stupid comment error causing save issues
1.3.1
- SVN failure to include importer files!
1.3
1.2
- Major fix for theme’s that use their own custom Walkers, thanks to Evan Stein @vanpop http://vanpop.com/
- Instead of a custom nav Walker, menu items are controlled through the wp_get_nav_menu_items filter
- Remove the custom nav Walker code
1.1.1
- Fix link to plugin site
- Fix labels in admin Walker
1.1
1.0