Fix template modified return value for file templates - #12711
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
This PR updates the Templates REST API to avoid returning an invalid modified value (false) for file-backed templates by returning null instead, and aligns the REST schema/tests with that behavior.
Changes:
- Return
nullformodifiedwhen a template has no modification date (e.g., file-backed templates). - Update the
modifiedschema type to allownull(string|null). - Add PHPUnit coverage for the
modifiedresponse value and schema.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/phpunit/tests/rest-api/wpRestTemplatesController.php | Adds tests asserting file-backed templates expose modified as null and that the schema allows null. |
| src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php | Returns null for empty modified and updates the modified schema type to `string |
Comments suppressed due to low confidence (1)
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php:791
dateis documented in the schema asstring|null, but file-backed templates set$template->datetonull(see_build_block_template_result_from_file()), which makesmysql_to_rfc3339()returnfalse. That means the REST response can still violate the schema for file-backed templates.
if ( rest_is_field_included( 'date', $fields ) ) {
$data['date'] = mysql_to_rfc3339( $template->date );
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Changes will be included here: #12709 |
Trac ticket: https://core.trac.wordpress.org/ticket/65730
Backports: WordPress/gutenberg#80733
What?
Recently we added the
datefield for template and template parts (https://core.trac.wordpress.org/ticket/65049) and it was noted that the returned value from REST API could returnfalsefor file templates. This will be fixed here: https://core.trac.wordpress.org/ticket/65728 for7.1.While looking into the above issue, I observed that we have the same issue for
modifiedproperty since6.3.We should update the type to be the same with
datetostring|nulland not returnfalsefor file templates.This PR updates the
modifiedprop to also returnnullfor file templates.Testing instructions
const templates = await wp.apiFetch( { path: '/wp/v2/templates?per_page=100' } );. Then inspecttemplatesmodifiedisnullfor file templates.Use of AI Tools
Opus 5 with direction, changes and review
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.