WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/20/2019 01:46:20 PM (16 months ago)
Author:
SergeyBiryukov
Message:

Date/Time: Add more supported formats to wp_maybe_decline_date().

Props SergeyBiryukov, Rarst.
Fixes #37411.

File:
1 edited

Legend:

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

    r45473 r45555  
    220220     */
    221221    if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
     222
     223        $months          = $wp_locale->month;
     224        $months_genitive = $wp_locale->month_genitive;
     225
    222226        // Match a format like 'j F Y' or 'j. F'
    223227        if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
    224             $months          = $wp_locale->month;
    225             $months_genitive = $wp_locale->month_genitive;
    226228
    227229            foreach ( $months as $key => $month ) {
     
    231233            foreach ( $months_genitive as $key => $month ) {
    232234                $months_genitive[ $key ] = ' ' . $month . '$1';
     235            }
     236
     237            $date = preg_replace( $months, $months_genitive, $date );
     238        }
     239
     240        // Match a format like 'F jS' or 'F j' and change it to 'j F'
     241        if ( @preg_match( '#^[^\d ]+ \d{1,2}(st|nd|rd|th)? #u', trim( $date ) ) ) {
     242            foreach ( $months as $key => $month ) {
     243                $months[ $key ] = '#' . $month . ' (\d{1,2})(st|nd|rd|th)?#u';
     244            }
     245
     246            foreach ( $months_genitive as $key => $month ) {
     247                $months_genitive[ $key ] = '$1 ' . $month;
    233248            }
    234249
Note: See TracChangeset for help on using the changeset viewer.