[wp-trac] [WordPress Trac] #54304: Expose menu data public in Menus REST API

WordPress Trac noreply at wordpress.org
Thu Nov 11 00:29:44 UTC 2021


#54304: Expose menu data public in Menus REST API
--------------------------+-----------------------------
 Reporter:  spacedmonkey  |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  REST API      |     Version:  4.7
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  rest-api
--------------------------+-----------------------------

Comment (by spacedmonkey):

 As a talking point I have create a POC PR at [https://github.com/WordPress
 /wordpress-develop/pull/1863 #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.

 {{{#!php
 apply_filters( 'wp_get_nav_menu_show_in_rest', false, $menu_obj, $menu )
 }}}

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

 {{{#!php
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54304#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list