Questions the author answers
I don’t see Appearance > Menus. Where are the settings?
Block themes, such as Twenty Twenty-Five, use the Navigation block instead of classic menus, so WordPress hides Appearance > Menus.
Since version 3.0.0, the Nav Menu Roles settings are in the Site Editor instead:
- Go to Appearance > Editor > Navigation and edit your menu.
- Select a link or submenu.
- In the block settings sidebar, open the “Nav Menu Roles” panel.
I don’t see the Nav Menu Roles options in Appearance > Menus?
Nav Menu Roles adds its options through the wp_nav_menu_item_custom_fields hook, which has been part of WordPress since 5.4. If a theme or plugin replaces the menu editor’s Walker and leaves that hook out, no plugin can add fields there.
I’m using XYZ Membership plugin and I don’t see its “levels”?
There are apparently a few membership plugins out there that don’t use traditional WordPress roles/capabilities. My plugin will list any role registered in the traditional WordPress way. If your membership plugin is using some other system, then Nav Menu Roles won’t work with it out of the box.
Existing Compatibility Plugins
- Wishlists Memberships
- WooCommerce Memberships
If your membership plugin is not listed here, you may be able to use the above bridge plugins as a template. Scroll down to the bottom of the main plugin file and you will see a section for “Helper Functions”. If you modify the 3 wrapper functions according to your membership plugin’s logic, the rest of the plugin should handle the integration with Nav Menu Roles.
Adding a new “role”
The roles in NMR are filterable distinct from the global $wp_roles. This allows for compatibility to be added between plugins that don’t use the core roles to determine access, like some membership plugins.
/** * Add custom roles to Nav Menu Roles menu list * param: $roles an array of all available roles, by default is global $wp_roles * return: array */ function kia_new_roles( $roles ) { $roles['new-role-key'] =…
Sort the roles alphabetically
Add the following snippet to your theme’s functions.php file:
/* * Sort the NMR roles * @param: $roles an array of all available roles with ID=>Name * @return: array */ function kia_sort_roles( $roles ) { if ( is_admin() ) { $array_lowercase = array_map( 'strtolower', $roles ); array_multisort( $array_lowercase, SORT_ASC, SORT_STRING, $roles ); return $roles; } } add_filter( 'nav_menu_roles', 'kia_sort_roles' );