| 3824 | | if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' === $postarr['post_date'] ) { |
| 3825 | | if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) { |
| 3826 | | $post_date = current_time( 'mysql' ); |
| 3827 | | } else { |
| 3828 | | $post_date = get_date_from_gmt( $postarr['post_date_gmt'] ); |
| 3829 | | } |
| 3830 | | } else { |
| 3831 | | $post_date = $postarr['post_date']; |
| 3832 | | } |
| 3833 | | |
| 3834 | | // Validate the date. |
| 3835 | | $mm = substr( $post_date, 5, 2 ); |
| 3836 | | $jj = substr( $post_date, 8, 2 ); |
| 3837 | | $aa = substr( $post_date, 0, 4 ); |
| 3838 | | $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date ); |
| 3839 | | if ( ! $valid_date ) { |
| | 3826 | $post_date = resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] ); |
| | 3827 | if ( ! $post_date ) { |
| | 4513 | * Resolve the mysql-formatted post date from provided date and date GMT strings. |
| | 4514 | * |
| | 4515 | * @param string $date The date in mysql format. |
| | 4516 | * @param string $date_gmt The GMT date in mysql format. |
| | 4517 | * @return string|false A valid Gregorian-calendar date string, or false on failure. |
| | 4518 | */ |
| | 4519 | function resolve_post_date( $date = '', $date_gmt = '' ) { |
| | 4520 | // If the date is empty, set the date to now. |
| | 4521 | if ( empty( $date ) || '0000-00-00 00:00:00' === $date ) { |
| | 4522 | if ( empty( $date_gmt ) || '0000-00-00 00:00:00' === $date_gmt ) { |
| | 4523 | $date = current_time( 'mysql' ); |
| | 4524 | } else { |
| | 4525 | $date = get_date_from_gmt( $date_gmt ); |
| | 4526 | } |
| | 4527 | } |
| | 4528 | |
| | 4529 | // Validate the date. |
| | 4530 | $mm = substr( $date, 5, 2 ); |
| | 4531 | $jj = substr( $date, 8, 2 ); |
| | 4532 | $aa = substr( $date, 0, 4 ); |
| | 4533 | $valid_date = wp_checkdate( $mm, $jj, $aa, $date ); |
| | 4534 | if ( ! $valid_date ) { |
| | 4535 | return false; |
| | 4536 | } |
| | 4537 | return $date; |
| | 4538 | } |
| | 4539 | |
| | 4540 | /** |