Changeset 50012 for trunk/src/wp-includes/post.php
- Timestamp:
- 01/25/2021 01:06:25 AM (5 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/post.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r49986 r50012 3703 3703 'import_id' => 0, 3704 3704 'context' => '', 3705 'post_date' => '', 3706 'post_date_gmt' => '', 3705 3707 ); 3706 3708 … … 3836 3838 3837 3839 /* 3838 * If the post date is empty (due to having been new or a draft) and status3839 * i s not 'draft' or 'pending', set dateto now.3840 * Resolve the post date from any provided post date or post date GMT strings; 3841 * if none are provided, the date will be set to now. 3840 3842 */ 3841 if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' === $postarr['post_date'] ) { 3842 if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) { 3843 $post_date = current_time( 'mysql' ); 3844 } else { 3845 $post_date = get_date_from_gmt( $postarr['post_date_gmt'] ); 3846 } 3847 } else { 3848 $post_date = $postarr['post_date']; 3849 } 3850 3851 // Validate the date. 3852 $mm = substr( $post_date, 5, 2 ); 3853 $jj = substr( $post_date, 8, 2 ); 3854 $aa = substr( $post_date, 0, 4 ); 3855 $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date ); 3856 if ( ! $valid_date ) { 3843 $post_date = wp_resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] ); 3844 if ( ! $post_date ) { 3857 3845 if ( $wp_error ) { 3858 3846 return new WP_Error( 'invalid_date', __( 'Invalid date.' ) ); … … 4537 4525 // wp_publish_post() returns no meaningful value. 4538 4526 wp_publish_post( $post_id ); 4527 } 4528 4529 /** 4530 * Uses wp_checkdate to return a valid Gregorian-calendar value for post_date. 4531 * If post_date is not provided, this first checks post_date_gmt if provided, 4532 * then falls back to use the current time. 4533 * 4534 * For back-compat purposes in wp_insert_post, an empty post_date and an invalid 4535 * post_date_gmt will continue to return '1970-01-01 00:00:00' rather than false. 4536 * 4537 * @since 5.7.0 4538 * 4539 * @param string $post_date The date in mysql format. 4540 * @param string $post_date_gmt The GMT date in mysql format. 4541 * @return string|false A valid Gregorian-calendar date string, or false on failure. 4542 */ 4543 function wp_resolve_post_date( $post_date = '', $post_date_gmt = '' ) { 4544 // If the date is empty, set the date to now. 4545 if ( empty( $post_date ) || '0000-00-00 00:00:00' === $post_date ) { 4546 if ( empty( $post_date_gmt ) || '0000-00-00 00:00:00' === $post_date_gmt ) { 4547 $post_date = current_time( 'mysql' ); 4548 } else { 4549 $post_date = get_date_from_gmt( $post_date_gmt ); 4550 } 4551 } 4552 4553 // Validate the date. 4554 $month = substr( $post_date, 5, 2 ); 4555 $day = substr( $post_date, 8, 2 ); 4556 $year = substr( $post_date, 0, 4 ); 4557 4558 $valid_date = wp_checkdate( $month, $day, $year, $post_date ); 4559 4560 if ( ! $valid_date ) { 4561 return false; 4562 } 4563 return $post_date; 4539 4564 } 4540 4565
Note: See TracChangeset
for help on using the changeset viewer.