Changeset 47078
- Timestamp:
- 01/17/2020 01:10:57 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r47060 r47078 287 287 288 288 $date = $datetime->format( $new_format ); 289 $date = wp_maybe_decline_date( $date );289 $date = wp_maybe_decline_date( $date, $format ); 290 290 } 291 291 … … 313 313 * 314 314 * @since 4.4.0 315 * @since 5.4.0 The `$format` parameter was added. 315 316 * 316 317 * @global WP_Locale $wp_locale WordPress date and time locale object. 317 318 * 318 * @param string $date Formatted date string. 319 * @param string $date Formatted date string. 320 * @param string $format Optional. Date format to check. Default empty string. 319 321 * @return string The date, declined if locale specifies it. 320 322 */ 321 function wp_maybe_decline_date( $date ) {323 function wp_maybe_decline_date( $date, $format = '' ) { 322 324 global $wp_locale; 323 325 … … 340 342 * and decline the month. 341 343 */ 342 if ( preg_match( '#\b\d{1,2}\.? [^\d ]+\b#u', $date ) ) { 344 if ( $format ) { 345 $decline = preg_match( '#[dj]\.? F#', $format ); 346 } else { 347 // If the format is not passed, try to guess it from the date string. 348 $decline = preg_match( '#\b\d{1,2}\.? [^\d ]+\b#u', $date ); 349 } 350 351 if ( $decline ) { 343 352 foreach ( $months as $key => $month ) { 344 353 $months[ $key ] = '# ' . preg_quote( $month, '#' ) . '\b#u'; … … 356 365 * and change it to declined 'j F'. 357 366 */ 358 if ( preg_match( '#\b[^\d ]+ \d{1,2}(st|nd|rd|th)?\b#u', trim( $date ) ) ) { 367 if ( $format ) { 368 $decline = preg_match( '#F [dj]#', $format ); 369 } else { 370 // If the format is not passed, try to guess it from the date string. 371 $decline = preg_match( '#\b[^\d ]+ \d{1,2}(st|nd|rd|th)?\b#u', trim( $date ) ); 372 } 373 374 if ( $decline ) { 359 375 foreach ( $months as $key => $month ) { 360 376 $months[ $key ] = '#\b' . preg_quote( $month, '#' ) . ' (\d{1,2})(st|nd|rd|th)?\b#u';
Note: See TracChangeset
for help on using the changeset viewer.