Check postId returns a published wp_template_part (#26734) #26812
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR implements some additional tests when loading a template part by
postId
.If the post type exists but it's not a
wp_template_part
or the post status is notpublish
then the template is not loaded.The template loading logic is now slightly different from before.
If the
postId
is set and subsequently determined to be invalid then the template part is not loaded.To help with problem determination the "Template Part Not Found" message now includes the
slug
.How has this been tested?
Using Twenty Twenty-One Blocks I created a
404.html
template file which contained.I adjusted the
postId
attribute for each test, where the URL was for content that couldn't be found.header
template part.This change prevents posts which are not of the correct post type and status from being loaded as template parts.
It doesn't deal with other problems with invalid attributes.
In the third test the postId loaded was a template part but it was not for the given
slug
and may not have been for the selectedtheme
. This will have to be addressed once the requirements are better understood.Screenshots
Types of changes
Fixes #26734
Checklist: