Open westonruter opened 8 years ago
Great writeup, Weston :+1:
Added points contrasting how widget instances and nav menu items are identified, with widgets being addressed in a similar way to terms prior to term splitting. Opened core ticket to harmonize by storing widgets in custom post type: https://core.trac.wordpress.org/ticket/35669
Widgets and nav menus are very similar in how they are structured in that both consist of collections of items which can be ordered. Indeed, nav menus could be entirely removed from core and in their place widgets could be used to build out navigation, with a “nav menu item” widget that has all the properties of a nav menu item. Nevertheless, there are some big differences in how widgets and nav menus are represented in the WP DB and as such there are certain restrictions on how they can be manipulated, but it would be great to align the REST APIs to reduce the cognitive load by harmonizing the interfaces.
Current: Nav Menus
nav_menu_item
post type.nav_menu
taxonomy.post.menu_order
.post.menu_order
, a nav menu item cannot be associated with more than one nav menu since there is only one position available.Current: Widgets
widget_text
contains a serialized array of all widget instances, where the array indicies indicate the widget numbers which then get used to construct widget IDs such astext-123
).id_base
since thenumber
is merely an array index for the array of widgets of that type. In this way, widgets in Core are currently in a similar situation as shared terms in Core, where a taxonomy term could not be uniquely identified by a term ID alone and a taxonomy name had to be supplied as well. For more information, see https://github.com/WP-API/wp-api-menus-widgets-endpoints/issues/12#issuecomment-177275265.sidebars_widgets
option which consists of an array of arrays, keyed by the sidebar ID and with the values being arrays of widget IDs for the respective sidebars.sidebars_widgets
option. Technically a widget could appear in multiple sidebars, but the UI does not support this.Harmonization possibilities
nav_menu_item_positions
, consisting of a list of post IDs).id_base
. Sidebars could be taxonomy terms, with the widget positions stored in term meta. See #35669.