diff --git src/wp-includes/post.php src/wp-includes/post.php
index 5ef96b3..fe4c0e9 100644
|
|
|
function wp_insert_post( $postarr, $wp_error = false ) { |
| 2817 | 2817 | } |
| 2818 | 2818 | |
| 2819 | 2819 | // If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now |
| 2820 | | if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date ) |
| 2821 | | $post_date = current_time('mysql'); |
| | 2820 | if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date ) { |
| | 2821 | if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) |
| | 2822 | $post_date = current_time('mysql'); |
| | 2823 | else |
| | 2824 | $post_date = get_date_from_gmt($post_date_gmt); |
| | 2825 | } |
| 2822 | 2826 | |
| 2823 | 2827 | // validate the date |
| 2824 | 2828 | $mm = substr( $post_date, 5, 2 ); |
| … |
… |
function wp_insert_post( $postarr, $wp_error = false ) { |
| 2839 | 2843 | $post_date_gmt = '0000-00-00 00:00:00'; |
| 2840 | 2844 | } |
| 2841 | 2845 | |
| 2842 | | if ( $update || '0000-00-00 00:00:00' == $post_date ) { |
| | 2846 | if ( $update ) { |
| 2843 | 2847 | $post_modified = current_time( 'mysql' ); |
| 2844 | 2848 | $post_modified_gmt = current_time( 'mysql', 1 ); |
| 2845 | 2849 | } else { |
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
index e8074e9..a675b03 100644
|
|
|
class Tests_Post extends WP_UnitTestCase { |
| 865 | 865 | $this->assertEquals( 9, $after_trash_counts->publish ); |
| 866 | 866 | $this->assertNotEquals( $initial_counts->publish, $after_trash_counts->publish ); |
| 867 | 867 | } |
| | 868 | |
| | 869 | function test_wp_insert_post_should_respect_post_date_gmt() { |
| | 870 | $post = array( |
| | 871 | 'post_author' => $this->author_id, |
| | 872 | 'post_status' => 'publish', |
| | 873 | 'post_content' => rand_str(), |
| | 874 | 'post_title' => rand_str(), |
| | 875 | 'post_date_gmt' => '2014-01-01 12:00:00', |
| | 876 | ); |
| | 877 | |
| | 878 | // insert a post and make sure the ID is ok |
| | 879 | $id = wp_insert_post($post); |
| | 880 | |
| | 881 | $out = get_post($id); |
| | 882 | |
| | 883 | $this->assertEquals($post['post_content'], $out->post_content); |
| | 884 | $this->assertEquals($post['post_title'], $out->post_title); |
| | 885 | $this->assertEquals($post['post_author'], $out->post_author); |
| | 886 | $this->assertEquals(get_date_from_gmt($post['post_date_gmt']), $out->post_date); |
| | 887 | $this->assertEquals($post['post_date_gmt'], $out->post_date_gmt); |
| | 888 | } |
| 868 | 889 | } |