Make WordPress Core

Ticket #15946: 15946.3.diff

File 15946.3.diff, 2.2 KB (added by oso96_2000, 10 years ago)

Refreshed patch

  • src/wp-includes/post-functions.php

    diff --git src/wp-includes/post-functions.php src/wp-includes/post-functions.php
    index a9f1ffc..5701aec 100644
    function _post_type_meta_capabilities( $capabilities = null ) { 
    13301330 * @since 4.3.0 Added the `featured_image`, `set_featured_image`, `remove_featured_image`,
    13311331 *              and `use_featured_image` labels.
    13321332 * @since 4.4.0 Added the `insert_into_item` and `uploaded_to_this_item` labels.
    1333  * 
     1333 *
    13341334 * @access private
    13351335 *
    13361336 * @param object $post_type_object Post type object.
    function wp_insert_post( $postarr, $wp_error = false ) { 
    30123012         * is not 'draft' or 'pending', set date to now.
    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                }
     3020
    30163021        } else {
    30173022                $post_date = $postarr['post_date'];
    30183023        }
  • tests/phpunit/tests/post.php

    diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
    index b3d7b0a..403258e 100644
    class Tests_Post extends WP_UnitTestCase { 
    12181218
    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}