Opened 8 years ago
Closed 8 years ago
#38698 closed defect (bug) (fixed)
REST API: Enable page templates for all post types
Reported by: | swissspidy | Owned by: | rmccue |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests |
Focuses: | rest-api | Cc: |
Description
[38951] enabled setting custom templates for all templates and not just pages.
With that being said, I just noticed that WP_REST_Posts_Controller::get_item_schema()
still has a 'page' === $this->post_type
check.
Attachments (3)
Change History (12)
#2
in reply to:
↑ 1
@
8 years ago
Replying to danielbachhuber:
Is there a
post_type_supports
opt-in / -out for templates? I can see cases where automatically adding templates to some post types would be unexpected.
Nope. All post_type
s support page templates now - as long as the theme includes templates for that post type.
As in the patch wp_get_theme()->get_page_templates( null, $this->post_type )
is probably the best way to determine if there's page templates available for the current post type - as even pages can have no templates, perhaps the if
should jue be changed to check that instead (So if the site has no page templates available for post_type = page
, it's not exposed in the API)
This ticket was mentioned in Slack in #core by helen. View the logs.
8 years ago
#5
follow-up:
↓ 6
@
8 years ago
In 38698.2.diff:
- Fix documentation
- Change conditional to only expose template option when there's at least 1 template (what about back compat?)
- Adds a unit test for when there's no template.
#6
in reply to:
↑ 5
@
8 years ago
Replying to swissspidy:
- Change conditional to only expose template option when there's at least 1 template (what about back compat?)
Schemas are meant to be fixed, meaning template
should always be an attribute on a Post or Page. enum
can be empty if there are no templates present.
See format
and the code around $fixed_schemas
for an analogue. template
likely deserves to be handled by $fixed_schemas
too.
#7
@
8 years ago
@danielbachhuber Thanks for the quick feedback!
As far as I can see, $fixed_schemas
is used for handling post type attributes, but page templates are not handled via post type attributes.
I removed the conditional check in the latest patch and will leave the rest for y'all to decide.
Is there a
post_type_supports
opt-in / -out for templates? I can see cases where automatically adding templates to some post types would be unexpected.