-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
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 a null 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.
// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
// is set in `wp_debug_mode()`.
$is_debug = WP_DEBUG && WP_DEBUG_DISPLAY;
if ( is_null( $content ) && $is_debug ) {During debugging $content is indeed null but $is_debug is false, so the failure case is unhandled and null is passed to shortcode_unautop leading to the crash
Step-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:
<!-- wp:template-part {"slug":"footer","theme":"my-theme"} /-->
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