diff --git a/src/wp-includes/post-functions.php b/src/wp-includes/post-functions.php index 1d6ae6fc39..05663968de 100644 --- a/src/wp-includes/post-functions.php +++ b/src/wp-includes/post-functions.php @@ -3042,7 +3042,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { // These variables are needed by compact() later. $post_content_filtered = $postarr['post_content_filtered']; - $post_author = empty( $postarr['post_author'] ) ? $user_id : $postarr['post_author']; + $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id; $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status']; $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : ''; $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : ''; diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index d6ce0309e6..b3d7b0a73a 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -1200,4 +1200,22 @@ class Tests_Post extends WP_UnitTestCase { // Teardown wp_set_current_user( $old_uid ); } + + /** + * @ticket 32585 + */ + public function test_wp_insert_post_author_zero() { + $post_id = $this->factory->post->create( array( 'post_author' => 0 ) ); + + $this->assertEquals( 0, get_post( $post_id )->post_author ); + } + + /** + * @ticket 32585 + */ + public function test_wp_insert_post_author_null() { + $post_id = $this->factory->post->create( array( 'post_author' => null ) ); + + $this->assertEquals( $this->author_id, get_post( $post_id )->post_author ); + } }