[wp-trac] [WordPress Trac] #60800: Twenty Twenty-One: prevent PHP 8 fatal error from non-string in $tags_list

WordPress Trac noreply at wordpress.org
Wed Apr 3 06:17:52 UTC 2024


#60800: Twenty Twenty-One: prevent PHP 8 fatal error from non-string in $tags_list
-------------------------------------------------+-------------------------
 Reporter:  josephscott                          |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  6.6
Component:  Bundled Theme                        |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  good-first-bug has-patch changes-    |     Focuses:
  requested                                      |
-------------------------------------------------+-------------------------
Changes (by devsahadat):

 * keywords:  good-first-bug has-patch => good-first-bug has-patch changes-
     requested


Comment:

 To address the issue encountered in the
 twenty_twenty_one_entry_meta_footer() function within /inc/template-
 tags.php, it's imperative to ensure that the $tags_list variable holds a
 string value before being passed to the printf() function. This adjustment
 is crucial for maintaining compatibility, particularly with PHP 8.1.

 Below is the proposed modification to the code:

 {{{

 $tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
 if ( is_string( $tags_list ) ) { // Adding this check ensures $tags_list
 is a string
     if ( $tags_list ) {
         printf(
             /* translators: %s: List of tags. */
             '<span class="tags-links">' . esc_html__( 'Tagged %s',
 'twentytwentyone' ) . '</span>',
             $tags_list // phpcs:ignore WordPress.Security.EscapeOutput
         );
     }
 }

 }}}

 By implementing this adjustment, the printf() function will only execute
 if $tags_list is indeed a string. Consequently, this preemptive validation
 mitigates the occurrence of fatal errors, specifically those stemming from
 $tags_list being a WP_Error object under PHP 8.1.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60800#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list