[wp-trac] [WordPress Trac] #59318: Bloc Themes Fatal Error in PHP 8.1 When Referring To Missing Template Parts
WordPress Trac
noreply at wordpress.org
Fri Sep 8 14:32:27 UTC 2023
#59318: Bloc Themes Fatal Error in PHP 8.1 When Referring To Missing Template Parts
--------------------------+-----------------------------
Reporter: TJNowell | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: 6.3.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
We have a system that manages template and template part posts, and have
noticed that if a template refers to a template part that no longer exists
or did not sync to the site, we get a cryptic PHP fatal error about
passing null to preg_replace:
{{{
preg_replace(): Passing null to parameter #3 ($subject) of type
array|string is deprecated
}}}
This occurs in template-part.php in the render_block_core_template_part
function when calling shortcode_unautop:
{{{
// Run through the actions that are typically taken on the_content.
$content = shortcode_unautop( $content );
}}}
In this case $content contains the value null. My expectation is that this
would fail gracefully, and there is a check if it is null further up the
function, but it only runs if $debug is true:
{{{
// 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 ) {
}}}
Meaning that unless WP_DEBUG and WP_DEBUG_DISPLAY are both set to true,
there is no protection against null being passed into shortcode_autop
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59318>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list