-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Initial work on a read-only sidebar endpoint has been done at https://github.com/martin-pettersson/wp-rest-api-sidebars
A sidebar resource can look like:
{
"name": "Sidebar Name",
"id": "sidebar-id",
"description": "Sidebar description...",
"class": "sidebar-class",
"before_widget": "<aside id=\"%1$s\" class=\"widget %2$s\">",
"after_widget": "<\/aside>",
"before_title": "<h1 class=\"widget-title\">",
"after_title": "<\/h1>",
}All of these would be readonly. As with the widgets endpoint, I suggest that rendered is not applicable to the REST API because a sidebar will have different content depending on the URL it is rendered onto.
Now, as for the actual list of widgets in a sidebar, I believe the representation should be just a list of widget IDs which would then allow the widgets assigned to a sidebar and their relative positions to be updated easily. The list of widget IDs can be exposed as a widgets property on the sidebar resource itself.
The sidebars endpoint should support returning the widgets among the _embedded, for example sidebars/:id:
{
"name": "Sidebar Name",
"id": "sidebar-id",
"description": "Sidebar description...",
"class": "sidebar-class",
"before_widget": "<aside id=\"%1$s\" class=\"widget %2$s\">",
"after_widget": "<\/aside>",
"before_title": "<h1 class=\"widget-title\">",
"after_title": "<\/h1>",
"widgets": [ "text-2", "search-4", "archives-3" ],
"_embedded": {
"widgets": [
{ "id": "text-2", "type":"text", "instance":{ "title": "Hello", "text": "World" } },
...
]
}
}Note that the widgets belonging to a sidebar could also be queried via a filter param, such as: wp/v2/widgets?filter[sidebar]=sidebar-1