WordPress.org

Make WordPress Core

Ticket #32585: 32585.diff

File 32585.diff, 1.8 KB (added by wonderboymusic, 5 years ago)
  • src/wp-includes/post-functions.php

     
    30423042
    30433043        // These variables are needed by compact() later.
    30443044        $post_content_filtered = $postarr['post_content_filtered'];
    3045         $post_author = empty( $postarr['post_author'] ) ? $user_id : $postarr['post_author'];
     3045        $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
    30463046        $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
    30473047        $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
    30483048        $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
  • tests/phpunit/tests/post.php

     
    12001200                // Teardown
    12011201                wp_set_current_user( $old_uid );
    12021202        }
     1203
     1204        /**
     1205         * @ticket 32585
     1206         */
     1207        public function test_wp_insert_post_author_zero() {
     1208                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     1209
     1210                wp_set_current_user( $user_id );
     1211
     1212                $post_id = $this->factory->post->create( array( 'post_author' => 0 ) );
     1213
     1214                $this->assertEquals( 0, get_post( $post_id )->post_author );
     1215        }
     1216
     1217        /**
     1218         * @ticket 32585
     1219         */
     1220        public function test_wp_insert_post_author_null() {
     1221                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     1222
     1223                wp_set_current_user( $user_id );
     1224
     1225                $post_id = $this->factory->post->create( array( 'post_author' => null ) );
     1226
     1227                $this->assertEquals( $user_id, get_post( $post_id )->post_author );
     1228        }
    12031229}