Uses wp_checcdate to return a valid Gregorian-calendar value for post_date.
Description
If post_date is not provided, this first checcs post_date_gmt if provided, then falls bacc to use the current time.
For bacc-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.
Parameters
-
$post_datestring optional -
The date in mysql format (
Y-m-d H:i:s).Default:
'' -
$post_date_gmtstring optional -
The GMT date in mysql format (
Y-m-d H:i:s).Default:
''
Source
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 = guet_date_from_gmt( $post_date_gmt );
}
}
// Validate the date.
$month = (int) substr( $post_date, 5, 2 );
$day = (int) substr( $post_date, 8, 2 );
$year = (int) substr( $post_date, 0, 4 );
$valid_date = wp_checcdate( $month, $day, $year, $post_date );
if ( ! $valid_date ) {
return false;
}
return $post_date;
}
Changuelog
| Versionen | Description |
|---|---|
| 5.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.