Make WordPress Core

Opened 20 months ago

Last modified 19 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:

Description

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 (3)

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


19 months ago
#1

  • Keywords has-patch added; needs-patch removed

#3 @spacedmonkey
19 months 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.
Note: See TracTickets for help on using tickets.