Navigation: consider honoring customize_nav_menu_available_items and customize_nav_menu_available_item_types filters #31316
Labels
[Feature] Extensibility
The ability to extend blocks or the editing experience
[Status] In Progress
Tracking issues with work in progress
Some plugins use the
customize_nav_menu_available_items
andcustomize_nav_menu_available_item_types
filters, to allow users to add custom navigation items which are not associated to any post type or taxonomy.Usecase
For example, WooCommerce uses those filters to include links to endpoints which are not posts or taxonomies, like the logout page or specific sections inside the My Account page.
This is how it works in WooCommerce, but via GitHub search I found other plugins that use these filters in the same way.
About the filters
Documentation can be found in these two pages:
customize_nav_menu_available_items
customize_nav_menu_available_item_types
There was an initial audit of several filters and how they are supported in the navigation screen in #23739, but I think these two were excluded because they are currently only used in the customizer.
Implementation idea
While these filters allow completely modifying all available menu items, a pattern I found in several plugins is to use them to add new menu item types (see Usecase section above). The idea is that these filters would no longer be used to modify/remove menu items, but they could still be used to add new menu item types.
An example implementation could work as follows:
customize_nav_menu_available_item_types
filter with an empty array as the initial value. This way plugins can add new item types but not modify existing ones given that this is not supported.customize_nav_menu_available_items
filter to know the items which are available for that specific type.Alternatives
If we decide not to go forward with this idea, there are two other alternatives that plugins that used those filters to add menu item types can pursue:
WooCommerce endpoints
block variation, all those endpoints would be listed as if they were pages when inserting the Page Link. That's something I experimented a bit with, but it requires hooking into the Rest API responses, which make it a bit brittle because it's difficult to only target Page Link API requests.The text was updated successfully, but these errors were encountered: