WordPress.org

Make WordPress Core

Changeset 42117


Ignore:
Timestamp:
11/06/2017 08:27:37 PM (3 years ago)
Author:
westonruter
Message:

Customize: Fall back to ISO date format for date/time control inputs if year, month, or day are missing from the date_format option.

Amends [42111].
Props dlh, westonruter.
Fixes #42394.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/customize/class-wp-customize-date-time-control.php

    r42111 r42117  
    101101
    102102        $date_format = get_option( 'date_format' );
    103         foreach ( array( 'Y', 'y', 'o' ) as $year_token ) {
    104             $date_format = preg_replace( '/(?<!\\\\)' . $year_token . '/', '%1$s', $date_format );
    105         }
    106         foreach ( array( 'F', 'm', 'M', 'n' ) as $month_token ) {
    107             $date_format = preg_replace( '/(?<!\\\\)' . $month_token . '/', '%2$s', $date_format );
    108         }
    109         foreach ( array( 'j', 'd' ) as $day_token ) {
    110             $date_format = preg_replace( '/(?<!\\\\)' . $day_token . '/', '%3$s', $date_format );
     103        $date_format = preg_replace( '/(?<!\\\\)[Yyo]/', '%1$s', $date_format );
     104        $date_format = preg_replace( '/(?<!\\\\)[FmMn]/', '%2$s', $date_format );
     105        $date_format = preg_replace( '/(?<!\\\\)[jd]/', '%3$s', $date_format );
     106
     107        // Fallback to ISO date format if year, month, or day are missing from the date format.
     108        if ( 1 !== substr_count( $date_format, '%1$s' ) || 1 !== substr_count( $date_format, '%2$s' ) || 1 !== substr_count( $date_format, '%3$s' ) ) {
     109            $date_format = '%1$s-%2$s-%3$s';
    111110        }
    112111        ?>
Note: See TracChangeset for help on using the changeset viewer.