-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return an empty object when no fallback templates are found (wp/v2/templates/lookup) #60925
Conversation
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @oryfoxer. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +5 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
91434e7
to
db773c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks right to me. It would probably be worth adding a unit test to catch this behavior in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
return defaultTemplateId | ||
? select( coreStore ).getEditedEntityRecord( | ||
'postType', | ||
'wp_template', | ||
defaultTemplateId | ||
) | ||
: null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the return type of getEditedEntityRecord
because sometimes the return type is important. And apparently it's gone through some recent changes; previously returning undefined
and now returning false
(see #60988). That being said, it seems null
is fine here even if that's different from the previous two return values with how getEditedPostTemplate
is used since it's only looking for falsy values, not anything specific.
I just cherry-picked this PR to the release/18.4 branch to get it included in the next release: afe6c6b |
…mplates/lookup) (#60925) Unlinked contributors: oryfoxer. Co-authored-by: creativecoder <[email protected]> Co-authored-by: joemcgill <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: david-binda <[email protected]>
Noting that there is a unit test that was added in the core patch (https://core.trac.wordpress.org/changeset/58079). I didn't duplicate it here in Gutenberg since the endpoint override here should be short lived, assuming the changes land in WP 6.6 as expected. |
…mplates/lookup) (WordPress#60925) Unlinked contributors: oryfoxer. Co-authored-by: creativecoder <[email protected]> Co-authored-by: joemcgill <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: david-binda <[email protected]>
…mplates/lookup) (WordPress#60925) Unlinked contributors: oryfoxer. Co-authored-by: creativecoder <[email protected]> Co-authored-by: joemcgill <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: david-binda <[email protected]>
What?
When a classic theme uses a theme.json file, it may not have any block templates available. This change modifies the
wp/v2/templates/lookup
to return an empty object when no fallback templates available, rather than an object full of empty properties, to avoid PHP errors being triggered.Fixes https://core.trac.wordpress.org/ticket/60909
Fixes #60974
Companion wordpress-develop PR: WordPress/wordpress-develop#6420
Why?
Testing Instructions
{ "version": 2 }
)/wp-json/wp/v2/templates/lookup
respond with an empty object in the browser network tab