Fix template date and modified return value for file templates - #12709
Fix template date and modified return value for file templates#12709ntsekouras wants to merge 2 commits into
date and modified return value for file templates#12709Conversation
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 ensures the REST API response for templates exposes a null date for file-backed templates, instead of the false value produced by mysql_to_rfc3339() for empty input—aligning the runtime value with the declared schema type (string|null).
Changes:
- Normalize
dateinWP_REST_Templates_Controller::prepare_item_for_response()to returnnullwhen the template has no date (file-backed templates). - Add a PHPUnit REST API test asserting
dateisnullfor a file-backed template. - Minor schema array formatting adjustment (alignment) near the
dateproperty.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/phpunit/tests/rest-api/wpRestTemplatesController.php | Adds regression test to ensure file-backed templates expose date: null via the REST API. |
| src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php | Prevents date from being serialized as false by returning null when no date exists, matching the schema’s allowed types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
date return value for file templatesdate and modified return value for file templates
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Trac ticket: https://core.trac.wordpress.org/ticket/65728
Follow up of: https://core.trac.wordpress.org/ticket/65049
Backports: WordPress/gutenberg#80733
As noted here: WordPress/gutenberg#77134 (comment), the new date field for templates and template parts can return false for file templates.
In practice this doesn't cause any errors but still the returned value should match the declared type (
string|null).With that comment I realized that
modifiedhas the exact same problem for many versions (since 6.3).We should update the type of
modifiedto be the same withdatetostring|nulland not returnfalsefor file templates.Testing instructions
const templates = await wp.apiFetch( { path: '/wp/v2/templates?per_page=100' } );. Then inspecttemplatesdateandmodifiedisnullfor 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.