-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Template part block - fix PHP notice for placeholder block. #30928
Conversation
if ( ! empty( $attributes['postId'] ) && get_post_status( $attributes['postId'] ) ) { | ||
$template_part_id = $attributes['postId']; | ||
// If we have a post ID and the post exists, which means this template part | ||
// is user-customized, render the corresponding post content. | ||
$content = get_post( $attributes['postId'] )->post_content; | ||
} elseif ( |
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.
Note - removing this section is unrelated to the error noted in the PR description.
This code block is no longer necessary since postId
has not been a valid attribute of the template part block for months now and content is always found via the slug
/theme
attributes.
Size Change: 0 B Total Size: 1.46 MB ℹ️ View Unchanged
|
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.
Assuming that with a template part placeholder, you mean a template part where one has not chosen whether to add a new or existing template part, then I am able to reproduce the PHP notice. Applying the PR solves it.
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.
Works as expected! 🚢
Description
When we attempt to load a post containing a template part block placeholder block a php notice is present:
Or on the front-end:
This is because when no content for the template part is resolved, a message is printed to notify the user using
sprintf
to attach theslug
attribute of the template part to the message:Since a template part placeholder block has no
slug
attribute, this also causessprintf
to throw the php notice. However, we should not be showing this message if noslug
attribute is present since absence of this attribute indicates a placeholder which by definition there should be no corresponding content found.In this PR we return nothing in the case of the placeholder, since no content is expected and no error message is required.
How has this been tested?
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).