Skip to content

Fix template date and modified return value for file templates - #12709

Open
ntsekouras wants to merge 2 commits into
WordPress:trunkfrom
ntsekouras:fix/65728
Open

Fix template date and modified return value for file templates#12709
ntsekouras wants to merge 2 commits into
WordPress:trunkfrom
ntsekouras:fix/65728

Conversation

@ntsekouras

@ntsekouras ntsekouras commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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 modified has the exact same problem for many versions (since 6.3).

We should update the type of modified to be the same with date to string|null and not return false for file templates.

Testing instructions

  1. Log in and ensure you have a block theme enabled
  2. Test the templates REST endpoint in dev tools: const templates = await wp.apiFetch( { path: '/wp/v2/templates?per_page=100' } );. Then inspect templates
  3. Observe that date and modified is null for 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.

@ntsekouras ntsekouras self-assigned this Jul 27, 2026
@ntsekouras ntsekouras added the bug label Jul 27, 2026
Copilot AI review requested due to automatic review settings July 27, 2026 10:53
@ntsekouras ntsekouras added the php Pull requests that update php code label Jul 27, 2026
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 date in WP_REST_Templates_Controller::prepare_item_for_response() to return null when the template has no date (file-backed templates).
  • Add a PHPUnit REST API test asserting date is null for a file-backed template.
  • Minor schema array formatting adjustment (alignment) near the date property.

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.

Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php Outdated
@ntsekouras ntsekouras changed the title Fix template date return value for file templates Fix template date and modified return value for file templates Jul 27, 2026
Copilot AI review requested due to automatic review settings July 27, 2026 15:06
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ntsekouras, tyxla.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug php Pull requests that update php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants