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
Fatal Error in PHP 8.1 when a template part reference is missing #54352
Comments
I've done some sleuthing around this. There are two PRs which look to contribute towards fixing this:
These need review so I'm moving this to |
Hi, |
Just updating that this is still an issue |
Punting this from the 6.5 release as we are less than a week away from beta 1 and it's not clear where the associated PR is: #54354 This was done after a review by the 6.5 core editor triage and tech leads. |
The summary is that the PR does what it needs to do and it makes obvious sense to add the check, but people struggled to reproduce the original error in order to test |
As best as I understand the bug, it can be phrased in two ways:
|
Hi @annezazu. This was my fault. I believe we should attempt to resolve for 6.5. I have re-tested the associated PR and it appears to resolve the Issue. I have asked for a confidence check from a few folks before we merge. Again apologies for the confusion regarding triage. |
Thanks for jumping back in with more context! Let's do it. This is part of the beauty of triaging is to uncover and move forward these things too. |
… non-debug environments (#54354) * Fix #54352 prevent php 8.1 fatal when template parts are not found in non-debug environments If the template part is not found content will be null which will cause fatal errors in PHP 8.1 when passed to shortcode_unautop, but this case is already handled if debug mode is turned on. This changeset allows it to be handled in all environments, not just when the admin has turned on WP_DEBUG and display debug messages * Update packages/block-library/src/template-part/index.php Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com> * Simplifies the check for a non-existent template part on render Incorporate feedback from @hellofromtonya https://github.com/WordPress/gutenberg/pull/54354/files#r1483032128 --------- Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: anton-vlasenko <antonvlasenko@git.wordpress.org> Co-authored-by: hellofromtonya <hellofromtonya@git.wordpress.org>
Description
Originally raised here: https://core.trac.wordpress.org/ticket/59318
If a block theme template references a template part via a template part block, but no part exists with the matching
slug
, a deprecation error occurs due to anull
value being sent to preg replace.In my particular case, the theme attribute was missing for unknown reasons on some templates loading the footer template part, and pages with those templates would trigger these fatal errors
Importantly, a check for this already exists, but only runs if the site is in debugging mode.
During debugging
$content
is indeednull
but$is_debug
isfalse
, so the failure case is unhandled andnull
is passed toshortcode_unautop
leading to the crashStep-by-step reproduction instructions
Place this in a template:
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->
Notice that in my situation the reason this was not working was the missing theme attribute:
It found the template part once
theme
had been added, but it should have failed gracefully and returned blank content instead of generating PHP fatal errors.Screenshots, screen recording, code snippet
No response
Environment info
WP 6.3, PHP 8.1
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: