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

WordPress Trac noreply at wordpress.org
Tue Feb 13 17:15:54 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 ryelle):

 [attachment:40878.3.diff] builds on @schlessera's earlier patch. I didn't
 see a controller for menu items, so this extends the
 `WP_REST_Posts_Controller` for GET requests to `menu-items`. You can now
 make requests like:

 - `GET /wp/v2/menu-items/` for a full list of menu items
 - `GET /wp/v2/menu-items/:id` for a single menu item
 - `GET /wp/v2/menu-items/?menus=2` for a list of menu items in menu with
 ID=2

 I've added these so that we can get a Custom/Navigation Menu block in
 gutenberg, see [https://github.com/WordPress/gutenberg/issues/1466 this
 issue] & PR (coming soon). These are read-only, and they contain the extra
 menu-related fields like `target`, `classes`, `attr_title`, etc. This also
 replaces the post's `link` with the menu destination link (the link to the
 `nav_menu_item` post type does not exist).

 For reference, the endpoints from schlessera's patch:

 - `GET /wp/v2/menus` for a list of available menus
 - `POST /wp/v2/menus` to create a new menu (taxonomy object)
 - `GET /wp/v2/menus/:id` for a single menu object
 - `POST /wp/v2/menus/:id` to update a single menu object
 - `DELETE /wp/v2/menus/:id` to delete a single menu object
 - `GET /wp/v2/menu-locations` for a list of available menu locations
 (theme-dependent)

 You can also do an `OPTIONS` request on any of these to get more info.

 Deleting a menu does not delete the sub-items in the menu, I think we'd
 want to call `wp_delete_nav_menu` in the menus controller. This also
 doesn't include any tests.

 ''Note, the two uploads (40878.diff & 40878.3.diff) are the same file, re-
 uploaded to get the `.3`''

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


More information about the wp-trac mailing list