Make WordPress Core

Changeset 34762


Ignore:
Timestamp:
10/02/2015 04:35:34 AM (9 years ago)
Author:
wonderboymusic
Message:

Posts: In wp_insert_post(), don't set post_date to current time if it can be derived from a passed value for post_date_gmt.

Adds unit tests.

Props oso96_2000, kawauso.
Fixes #15946.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-functions.php

    r34746 r34762  
    30133013     */
    30143014    if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' == $postarr['post_date'] ) {
    3015         $post_date = current_time( 'mysql' );
     3015        if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {
     3016            $post_date = current_time( 'mysql' );
     3017        } else {
     3018            $post_date = get_date_from_gmt( $postarr['post_date_gmt'] );
     3019        }
    30163020    } else {
    30173021        $post_date = $postarr['post_date'];
  • trunk/tests/phpunit/tests/post.php

    r34085 r34762  
    12191219        $this->assertEquals( $this->author_id, get_post( $post_id )->post_author );
    12201220    }
     1221
     1222    /**
     1223     * @ticket 15946
     1224     */
     1225    function test_wp_insert_post_should_respect_post_date_gmt() {
     1226        $post = array(
     1227            'post_author' => $this->author_id,
     1228            'post_status' => 'publish',
     1229            'post_content' => rand_str(),
     1230            'post_title' => rand_str(),
     1231            'post_date_gmt' => '2014-01-01 12:00:00',
     1232        );
     1233
     1234        // insert a post and make sure the ID is ok
     1235        $id = wp_insert_post($post);
     1236
     1237        $out = get_post($id);
     1238
     1239        $this->assertEquals($post['post_content'], $out->post_content);
     1240        $this->assertEquals($post['post_title'], $out->post_title);
     1241        $this->assertEquals($post['post_author'], $out->post_author);
     1242        $this->assertEquals(get_date_from_gmt($post['post_date_gmt']), $out->post_date);
     1243        $this->assertEquals($post['post_date_gmt'], $out->post_date_gmt);
     1244    }
    12211245}
Note: See TracChangeset for help on using the changeset viewer.