Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar endpoints #1

Open
westonruter opened this issue Jan 29, 2016 · 2 comments
Open

Sidebar endpoints #1

westonruter opened this issue Jan 29, 2016 · 2 comments

Comments

@westonruter
Copy link
Member

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

@NateWr
Copy link
Contributor

NateWr commented Jan 30, 2016

Sounds good.

Just to raise the issue we discussed about whether or not the REST API should be concerned with presentational information: do we want to return the class, before_widget, after_widget, before_title, and after_title params? Is this data that's stored in the database or registered dynamically with each page load?

I'm not sure whether these bits qualify as "data" or if they are merely convenient config params for template development that do not belong with the grouping resource we talked about.

@westonruter
Copy link
Member Author

Yeah, great points. These aren't stored in the database. They're only registered at runtime via PHP.

@kadamwhite kadamwhite transferred this issue from WP-API/menus-endpoints Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants