Feature: Expose post_types
field to Templates REST API
#7530
+10
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac Ticket: Core-61308
Overview
This pull request adds a new
post_types
field to the existing WordPress REST API endpoint for templates (/wp/v2/templates
). This enhancement allows users to filter templates based on the post types they are intended for, thereby improving usability and functionality in the site editor templates screen.Changes Made
Modified
get_item_schema()
:Added a new property, post_types, to the JSON schema for templates.
The post_types field is defined as an array of strings, describing the associated post types for each template.
Updated
prepare_item_for_response()
:Implemented logic to fetch and include the post_types information in the API response.
Ensured that the post_types field is populated based on the associated post types stored in the template's metadata.
Benefits
Improved Filtering
: Users can now filter templates directly by their associated post types, making it easier to find relevant templates for specific content types.Enhanced API Usability
: By exposing the post_types field, we align the API capabilities with user expectations and common use cases.