Make WordPress Core

Opened 4 months ago

Closed 3 months ago

Last modified 3 months ago

#60909 closed defect (bug) (fixed)

Classic Theme with theme.json attempts to load templates

Reported by: cookiesfordevo's profile CookiesForDevo Owned by: jorbin's profile jorbin
Milestone: 6.5.3 Priority: normal
Severity: normal Version: 6.5
Component: Themes Keywords: has-patch has-unit-tests fixed-major dev-reviewed
Focuses: Cc:

Description

With 6.5 if a classic theme has a theme.json, editing a post/page attempts to load templates resulting in a bevy of php warnings with the $template var being null inside prepare_item_for_response.

Tested with twentynineteen and adding a theme.json with only the version number.

[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "id" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 647
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "theme" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 651
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "content" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 658
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "content" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 662
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "slug" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 666
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "source" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 670
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "origin" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 674
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "type" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 678
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "description" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 682
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "title" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 690
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "wp_id" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 694
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "title" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 698
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "status" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 703
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "wp_id" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 707
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "has_theme_file" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 711
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "type" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 714
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "author" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 719
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "modified" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 727
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "type" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 769
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "author" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 829
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "type" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 769
[03-Apr-2024 13:59:04 UTC] PHP Warning:  Attempt to read property "id" on null in /app/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php on line 746
[03-Apr-2024 13:59:04 UTC] PHP Deprecated:  explode(): Passing null to parameter #2 ($string) of type string is deprecated in /app/wp-includes/block-template-utils.php on line 1076

Change History (27)

#1 @sabernhardt
4 months ago

  • Component changed from General to Themes

#2 @audrasjb
4 months ago

  • Milestone changed from Awaiting Review to 6.5.1

Hello and welcome to WordPress Core Trac, thanks for the ticket

Moving to 6.5.1 for investigation.

#3 @CookiesForDevo
4 months ago

Manually disabling support for block-templates does work around the issue:

add_action(
	'init',
	function () {
		remove_theme_support( 'block-templates' );
	},
	10,
	0,
);

#4 @britner
4 months ago

Hi, I can confirm this is a bug introduced in 6.5 and happens if a classic theme has a theme.json file or if a classic theme has enabled block templates through

add_theme_support( 'block-templates' );

This ticket was mentioned in Slack in #core by jorbin. View the logs.


4 months ago

This ticket was mentioned in Slack in #core-editor by jorbin. View the logs.


4 months ago

#7 @davidbaumwald
4 months ago

  • Milestone changed from 6.5.1 to 6.5.2

Milestone renamed

#8 @jorbin
4 months ago

  • Milestone changed from 6.5.2 to 6.5.3

#9 @jorbin
4 months ago

#60973 was marked as a duplicate.

#10 @jorbin
4 months ago

#60988 was marked as a duplicate.

This ticket was mentioned in Slack in #core by jorbin. View the logs.


4 months ago

This ticket was mentioned in Slack in #core-editor by grantmkin. View the logs.


4 months ago

This ticket was mentioned in Slack in #core by jorbin. View the logs.


4 months ago

#14 @grantmkin
4 months ago

From what I can tell, by testing the wp/v2/templates/lookup endpoint in WP 6.4 and looking through the commit history, the endpoint returning a null item when there are no block templates has been happening for some time. What changed with WP 6.5 was the page editor calling the endpoint on load, revealing the issue.

This ticket was mentioned in PR #6420 on WordPress/wordpress-develop by @grantmkin.


4 months ago
#15

  • Keywords has-patch has-unit-tests added

Modifies the wp/v2/templates/fallback endpoint to return a 404 error when no templates are found.

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

#17 @wildworks
3 months ago

A similar issue was reported with Gutenberg: https://github.com/WordPress/gutenberg/issues/60974

You can check the error log by accessing the link in the issue.

This ticket was mentioned in Slack in #core by grantmkin. View the logs.


3 months ago

This ticket was mentioned in Slack in #core by grantmkin. View the logs.


3 months ago

#20 @jorbin
3 months ago

Even though it feels unlikely that folks are using this endoint outside of the editor, ruturning a 404 rather than a 200 would be a breaking change that I think should be avoided, especially in a minor release.

What are the thoughts on if $fallback_template is falsey, to skip prepare_item_for_response and keep the return value the same.

This ticket was mentioned in Slack in #core by jorbin. View the logs.


3 months ago

#22 @grantmkin
3 months ago

What are the thoughts on if $fallback_template is falsey, to skip prepare_item_for_response and keep the return value the same.

I don't particularly like the inconsistency of other methods in the templates controller returning a 404 error when a template isn't found, but the fallback route returning a 200 status with an empty response. But I see how this makes sense for a minor release, to minimize changes.

I've updated the wordpress-develop PR to skip prepare_item_for_response and return an empty object when the fallback template isn't found.

#23 @jorbin
3 months ago

  • Owner set to jorbin
  • Resolution set to fixed
  • Status changed from new to closed

In 58079:

REST API: Return empty object when no fallback templates are found (wp/v2/templates/lookup)

This prevents a number of php notices that are surfaced due to the endpoint being called on load of the post editor even when there are no templates.

Props grantmkin, CookiesForDevo, britner, wildworks, jorbin.
Fixes #60909.

#24 @jorbin
3 months ago

  • Keywords fixed-major dev-feedback added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopeing for backport consideration

#25 @joemcgill
3 months ago

  • Keywords dev-reviewed added; dev-feedback removed

[58079] looks good to backport 👍🏻

#26 @jorbin
3 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 58080:

REST API: Return empty object when no fallback templates are found (wp/v2/templates/lookup)

This prevents a number of php notices that are surfaced due to the endpoint being called on load of the post editor even when there are no templates.

Reviewed by joemcgill.
Merges [58079] to the 6.5 branch.

Props grantmkin, CookiesForDevo, britner, wildworks, jorbin.
Fixes #60909.

Note: See TracTickets for help on using tickets.