wp_resolve_post_date()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_resolve_post_date( string $post_date = '', string $post_date_gmt = '' ): string|false
Описание
Если post_date не указан, сначала проверяется post_date_gmt (если он задан), а затем используется текущее время.
В целях обратной совместимости в wp_insert_post пустой post_date и некорректный post_date_gmt по-прежнему возвращают ‘1970-01-01 00:00:00’, а не false.
Оригинал (английский)
If post_date is not provided, this first checks post_date_gmt if provided, then falls back to use the current time.
For back-compat purposes in wp_insert_post, an empty post_date and an invalid post_date_gmt will continue to return ‘1970-01-01 00:00:00’ rather than false.
Параметры
$post_date
string
необязательный
= ''
$post_date_gmt
string
необязательный
= ''
Возвращаемое значение
string|false
Исходный код
wp-includes/post.php:5423
function wp_resolve_post_date( $post_date = '', $post_date_gmt = '' ) {
// If the date is empty, set the date to now.
if ( empty( $post_date ) || '0000-00-00 00:00:00' === $post_date ) {
if ( empty( $post_date_gmt ) || '0000-00-00 00:00:00' === $post_date_gmt ) {
$post_date = current_time( 'mysql' );
} else {
$post_date = get_date_from_gmt( $post_date_gmt );
}
}
// Validate the date.
preg_match( '/^(\d{4})-(\d{1,2})-(\d{1,2})/', $post_date, $matches );
if ( empty( $matches ) || ! is_array( $matches ) || count( $matches ) < 4 ) {
return false;
}
$valid_date = wp_checkdate( $matches[2], $matches[3], $matches[1], $post_date );
if ( ! $valid_date ) {
return false;
}
return $post_date;
}
История изменений
| Версия | Описание |
|---|---|
| 5.7.0 | Introduced. |

