确定是否应拒绝日期。

原型

wp_maybe_decline_date( string $date )

描述

如果语言环境指定月份名称需要某种格式的属格案例(例如“j F Y”),则月份名称将替换为正确的格式。

参数

$date (string) (Required) 格式化日期字符串。

返回值

(string)  如果语言环境指定日期,则拒绝该日期。

源文件

路径:wp-includes/functions.php

<?php
...
function wp_maybe_decline_date( $date ) {
	global $wp_locale;
	// i18n functions are not available in SHORTINIT mode
	if ( ! function_exists( '_x' ) ) {
		return $date;
	}
	/* translators: If months in your language require a genitive case,
	 * translate this to 'on'. Do not translate into your own language.
	 */
	if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {
		// Match a format like 'j F Y' or 'j. F'
		if ( @preg_match( '#^d{1,2}.? [^d ]+#u', $date ) ) {
			$months          = $wp_locale->month;
			$months_genitive = $wp_locale->month_genitive;
			foreach ( $months as $key => $month ) {
				$months[ $key ] = '# ' . $month . '( |$)#u';
			}
			foreach ( $months_genitive as $key => $month ) {
				$months_genitive[ $key ] = ' ' . $month . '$1';
			}
			$date = preg_replace( $months, $months_genitive, $date );
		}
	}
	// Used for locale-specific rules
	$locale = get_locale();
	if ( 'ca' === $locale ) {
		// " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..."
		$date = preg_replace( '# de ([ao])#i', " d'\1", $date );
	}
	return $date;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_maybe_decline_date/