Make WordPress Core

Opened 3 years ago

Last modified 3 months ago

#54304 new defect (bug)

Expose menu data public in Menus REST API

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: has-patch
Focuses: rest-api Cc:


Menus endpoints will be added in #40878. However by default this data requires the user to be logged in with the correct capability to access this data.

There should be a way to allow developers or users to expose menu / menu item / menu location publically in REST API.

Change History (4)

This ticket was mentioned in PR #1863 on WordPress/wordpress-develop by spacedmonkey.

3 years ago

  • Keywords has-patch added; needs-patch removed

#3 @spacedmonkey
3 years ago

As a talking point I have create a POC PR at #1863.

What this does, add a filter new property to the WP_Term object for the menu called, show_in_rest. This property has a filter. To expose the data simple use this filter.

apply_filters( 'wp_get_nav_menu_show_in_rest', false, $menu_obj, $menu )

To make all the menus public, you simple need to this.

add_filter('wp_get_nav_menu_show_in_rest', '__return_true');

Having this filter on the menu level makes sense for a couple of reasons.

  • Adding a filter on menu item does make sense, as either you make the whole menu public or not all.
  • Location does not make sense, as some menus may not be used in locations, like widgets or other custom implements.
  • Menu, are already an object and is easy to add a property to it.

#4 @julianmar
3 months ago

It would be really nice to get this Feature. It would move WordPress to be easier to use as a Headless CMS.

Note: See TracTickets for help on using tickets.