[wp-trac] [WordPress Trac] #40878: Adding menus route

WordPress Trac noreply at wordpress.org
Fri Mar 16 14:03:09 UTC 2018


#40878: Adding menus route
------------------------------------+------------------------------
 Reporter:  dingo_bastard           |       Owner:
     Type:  feature request         |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  REST API                |     Version:  4.7
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:  rest-api
------------------------------------+------------------------------

Comment (by schlessera):

 I looked through my code to see how I handled the `menu-items` endpoint.

 I basically just reused the posts controller, by adding the following to
 the `register_post_type()` call for the `nav_menu_item` post type:

 {{{#!php
 'show_in_rest'          => true,
 'rest_base'             => 'menu-items',
 'rest_controller_class' => 'WP_REST_Posts_Controller',
 }}}

 Through all the built-in mechanisms that the controller, and more
 specifically the posts controller provide, this allows for all general
 manipulations you might need.

 Of course, as soon as we want to add menu-item-specific code, we'd need to
 extend the posts controller anyway, so @ryelle 's approach above makes
 sense.

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


More information about the wp-trac mailing list