Skip to content

Fix template modified return value for file templates - #12711

Closed
ntsekouras wants to merge 1 commit into
WordPress:trunkfrom
ntsekouras:fix/65730
Closed

Fix template modified return value for file templates#12711
ntsekouras wants to merge 1 commit into
WordPress:trunkfrom
ntsekouras:fix/65730

Conversation

@ntsekouras

Copy link
Copy Markdown
Contributor

Trac ticket: https://core.trac.wordpress.org/ticket/65730

Backports: WordPress/gutenberg#80733

What?

Recently we added the date field for template and template parts (https://core.trac.wordpress.org/ticket/65049) and it was noted that the returned value from REST API could return false for file templates. This will be fixed here: https://core.trac.wordpress.org/ticket/65728 for 7.1.

While looking into the above issue, I observed that we have the same issue for modified property since 6.3.

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

This PR updates the modified prop to also return null 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 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
Copilot AI review requested due to automatic review settings July 27, 2026 11:44
@ntsekouras ntsekouras added bug php Pull requests that update php code labels 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 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 null for modified when a template has no modification date (e.g., file-backed templates).
  • Update the modified schema type to allow null (string|null).
  • Add PHPUnit coverage for the modified response 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

  • date is documented in the schema as string|null, but file-backed templates set $template->date to null (see _build_block_template_result_from_file()), which makes mysql_to_rfc3339() return false. 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.

@ntsekouras

Copy link
Copy Markdown
Contributor Author

Changes will be included here: #12709

@ntsekouras ntsekouras closed this Jul 27, 2026
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.

2 participants