Make WordPress Core

Changeset 52136


Ignore:
Timestamp:
11/11/2021 04:27:44 PM (3 years ago)
Author:
hellofromTonya
Message:

Template: Fix "undefined index: 00" when archive month query is empty in wp_title().

When m query_tag has a valid year, i.e. ?m=2021, and there are posts for that year, substr() returns a false on PHP 5.6 and an empty string on PHP 7.0+. Passing either of those values to $wp_locale->get_month() results in a PHP notice on PHP 5.6 to PHP 7.4 and a PHP Warning on PHP 8.0+.

Why? The $month lookup table has zeroized keys from '01' to '12'. A empty value is passed to zeroise() returns '00' which is directly passed as a key in the month property. That key does not exist.

While $wp_locale->get_month() would benefit from guarding/validation, this fix ensures a falsey value is not passed as a month.

Tests are added including a test that fails with this fix not applied.

Follow-up to [801], [35294], [35624].

Props antpb, audrasjb, costdev, davidmosterd, drewapicture, herregroen, hellofromTonya, michelwppi, sergeybiryukov.
Fixes #31521.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r51957 r52136  
    13771377    if ( is_archive() && ! empty( $m ) ) {
    13781378        $my_year  = substr( $m, 0, 4 );
    1379         $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
     1379        $my_month = substr( $m, 4, 2 );
    13801380        $my_day   = (int) substr( $m, 6, 2 );
    1381         $title    = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
     1381        $title    = $my_year .
     1382            ( $my_month ? $t_sep . $wp_locale->get_month( $my_month ) : '' ) .
     1383            ( $my_day ? $t_sep . $my_day : '' );
    13821384    }
    13831385
Note: See TracChangeset for help on using the changeset viewer.