Skip to content
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

Check postId returns a published wp_template_part (#26734) #26812

Closed
wants to merge 1 commit into from

Conversation

bobbingwide
Copy link
Contributor

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 not publish 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.

<!-- wp:template-part {"slug":"issue-26734","theme":"twentytwentyone-blocks", "postId": 1 } /-->

I adjusted the postId attribute for each test, where the URL was for content that couldn't be found.

postId Referenced post type Referenced post status Result
1 post - Hello World n/a Template Part Not Found: issue-26734
11 wp_template_part draft Template Part Not Found: issue-26374
25 wp_template_part publish Displayed the 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 selected theme. This will have to be addressed once the requirements are better understood.

Screenshots

Types of changes

Fixes #26734

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@bobbingwide
Copy link
Contributor Author

What do I need to do to progress this PR?

Base automatically changed from master to trunk March 1, 2021 15:44
@youknowriad
Copy link
Contributor

Hi @bobbingwide sorry this took so long. I didn't see the PR personally. The PR seems good but there seem to be a conflict now, would you mind rebasing it?

@bobbingwide
Copy link
Contributor Author

I'll have a go if someone else doesn't get there first.

@david-szabo97
Copy link
Member

Closing this. postId isn't an attribute of the Template Part block anymore. We are using the theme and slug attributes to fetch the correct template part.

@bobbingwide
Copy link
Contributor Author

Oh good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gutenberg_render_block_core_template_part should validate postId attribute as ID for a wp_template_part post
5 participants