WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 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)

38698.diff (3.3 KB) - added by swissspidy 3 years ago.
38698.2.diff (3.3 KB) - added by swissspidy 3 years ago.
38698.3.diff (3.6 KB) - added by swissspidy 3 years ago.

Download all attachments as: .zip

Change History (12)

@swissspidy
3 years ago

#1 follow-up: @danielbachhuber
3 years ago

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.

#2 in reply to: ↑ 1 @dd32
3 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_types 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.


3 years ago

#4 @swissspidy
3 years ago

  • Owner set to swissspidy
  • Status changed from new to assigned

@swissspidy
3 years ago

#5 follow-up: @swissspidy
3 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 @danielbachhuber
3 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.

@swissspidy
3 years ago

#7 @swissspidy
3 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.

#8 @rmccue
3 years ago

  • Owner changed from swissspidy to rmccue
  • Status changed from assigned to reviewing

#9 @rmccue
3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 39182:

REST API: Include template in all post type schemas.

[38951] added templates to all post types, but didn't add them to the schema.

Props swissspidy.
Fixes #38698.

Note: See TracTickets for help on using tickets.