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. Built from https://develop.svn.wordpress.org/trunk@52136 git-svn-id: http://core.svn.wordpress.org/trunk@51728 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
51d95be654
commit
2ae0e77e47
|
@ -1376,9 +1376,11 @@ function wp_title( $sep = '»', $display = true, $seplocation = '' ) {
|
|||
// If there's a month.
|
||||
if ( is_archive() && ! empty( $m ) ) {
|
||||
$my_year = substr( $m, 0, 4 );
|
||||
$my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
|
||||
$my_month = substr( $m, 4, 2 );
|
||||
$my_day = (int) substr( $m, 6, 2 );
|
||||
$title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
|
||||
$title = $my_year .
|
||||
( $my_month ? $t_sep . $wp_locale->get_month( $my_month ) : '' ) .
|
||||
( $my_day ? $t_sep . $my_day : '' );
|
||||
}
|
||||
|
||||
// If there's a year.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.9-alpha-52135';
|
||||
$wp_version = '5.9-alpha-52136';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue