Make WordPress Core

Changeset 59870


Ignore:
Timestamp:
02/25/2025 10:38:42 PM (2 months ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-locale.php

    r59494 r59870  
    316316     *
    317317     * @param string|int $month_number '01' through '12'.
    318      * @return string Translated full month name.
     318     * @return string Translated full month name. If the month number is not found, an empty string is returned.
    319319     */
    320320    public function get_month( $month_number ) {
    321         return $this->month[ zeroise( $month_number, 2 ) ];
     321        $month_number = zeroise( $month_number, 2 );
     322        if ( ! isset( $this->month[ $month_number ] ) ) {
     323            return '';
     324        }
     325        return $this->month[ $month_number ];
    322326    }
    323327
Note: See TracChangeset for help on using the changeset viewer.