From 12eaef1dd97ce46d7e665c69764cdae7387b03cc Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Tue, 25 Feb 2025 22:38:42 +0000 Subject: [PATCH] Date/Time: Add sanitization to `WP_Locale::get_month()`. By adding a sanitization to `$wp_locale->get_month()`, this changeset prevents a PHP Warning: `Undefined array key "00"` caused by `single_month_title()`. This function previously assumed that `get_query_var( 'm' )` is always at least 6 digits, and always contains the year and the month, which is not necessarily true. Props apermo, audrasjb, xateman. Fixes #62824. git-svn-id: https://develop.svn.wordpress.org/trunk@59870 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-locale.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-locale.php b/src/wp-includes/class-wp-locale.php index a78617b5e3..0fcb130b81 100644 --- a/src/wp-includes/class-wp-locale.php +++ b/src/wp-includes/class-wp-locale.php @@ -315,10 +315,14 @@ class WP_Locale { * @since 2.1.0 * * @param string|int $month_number '01' through '12'. - * @return string Translated full month name. + * @return string Translated full month name. If the month number is not found, an empty string is returned. */ public function get_month( $month_number ) { - return $this->month[ zeroise( $month_number, 2 ) ]; + $month_number = zeroise( $month_number, 2 ); + if ( ! isset( $this->month[ $month_number ] ) ) { + return ''; + } + return $this->month[ $month_number ]; } /**