-
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
Fix #54352 prevent php 8.1 fatal when template parts are not found in non-debug environments #54354
Conversation
Noting that a PR was originally raised by @kadamwhite here WordPress/wordpress-develop#5177 which contains a small unit test for WP core |
@tomjn Thanks for the PR. Can I confirm whether this one is the canonical PR to fix #54352? I believe it is which is why I've now linked it up with the Issue and then moved the Issue to "Needs Review" on the WP 6.4 Board but I felt it was wise to check given your comment above. Also, apologies, but I was unable to replicate the original error. Perhaps it's due to my environment (I'm using |
It's likely the template part you're referencing exists, a reading of the code clearly indicates a failure point where a non string value could be passed through. Note that no testing has been done on 6.4, only 6.3. Note that the associated WP Trac ticket has a failing unit test that is fixed by this code change that was written by KAdam |
Thanks for the update 👍
Not unless I have a template part called I agree with your reading of the code, but I would like to be able to replicate. I'll continue in my efforts... |
In my original tests, the block template part was missing the theme attribute when I had the issue, which was the main reason it couldn't find the part |
I am not able to reproduce the fatal error, but I see a PHP warning for a different line, unaffected by the PR. So the warning shows when my template part slug is a non-existing template part, no matter if the PR is applied or not.
|
I would note that |
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 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. |
I'm going to re-test this. |
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.
Thank you for the additional testing instructions.
I felt this was worth revisiting as a bug so I re-tested this by:
- using PHP 8.1+
- setting WP_DEBUG to
false
. - creating a template part with a random slug to ensure it would not exist
I then loaded the page with that template on the front of the site.
Testing on trunk
Without the change in this PR, I didn't see an error, but I did see an empty template part output to the front of the site. This is because the code managed to reach the return which outputs the HTML without erroring:
return "<$html_tag $wrapper_attributes>" . str_replace( ']]>', ']]>', $content ) . "</$html_tag>"; |
I consider the empty template part to be a bug. Not sure if something changed and why I don't get the error that you saw.
Testing on this PR
With the change in this PR the code correctly exits execution of the remainder of the function regardless of the value of the WP_DEBUG.
On the front of the site no template part markup was output at all which is what I would consider correct.
I believe the fix is good, but I would appreciate a confidence check (maybe @anton-vlasenko ?).
I think we should also land the unit test coverage for this that you referenced. This can land directly in WP Core once this patch is in Core.
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.
Just a minor suggestion.
@tomjn Most of the test failures here look to be due to issues that were previously in evidence in Gutenberg If you:
...then the tests should pass. If would be ideal if this landed today so it was included in the final Gutenberg release for WP 6.5 which is happening at 16:00 UTC today. If it doesn't make it it will need a manual backport as a bug. |
… 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
Co-authored-by: Anton Vlasenko <[email protected]>
@getdave I rebased, just waiting for CI, also happy for any intervention that needs to happen so this isn't blocked by me |
Thank you. Unfortunately I cannot push to your fork otherwise I'd happily wrangle this on your behalf. |
@MaggieCabrera Can we bring this in to 17.7.0 RC? If it didn't make the cut please do add the |
This made it to the RC |
What?
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.
Closes #54352
Why?
Because it's fixing a fatal error on PHP 8.1+
How?
This change separates the debug part into a sub-condition so that it can return
''
if we are not in debugging mode.Testing Instructions
$debug
in the code has the value offalse
nottrue