WordPress.org

Make WordPress Core

Changeset 34085


Ignore:
Timestamp:
09/12/2015 06:53:56 PM (5 years ago)
Author:
wonderboymusic
Message:

In wp_insert_post(), when setting $post_author, use isset() instead of ! empty() to allow 0 to be passed as the value for $post_author.

Adds unit tests.

Props ericdaams, wonderboymusic.
Fixes #32585.

Location:
trunk
Files:
2 edited

Legend:

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

    r34082 r34085  
    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'] ) : '';
  • trunk/tests/phpunit/tests/post.php

    r34001 r34085  
    12011201        wp_set_current_user( $old_uid );
    12021202    }
     1203
     1204    /**
     1205     * @ticket 32585
     1206     */
     1207    public function test_wp_insert_post_author_zero() {
     1208        $post_id = $this->factory->post->create( array( 'post_author' => 0 ) );
     1209
     1210        $this->assertEquals( 0, get_post( $post_id )->post_author );
     1211    }
     1212
     1213    /**
     1214     * @ticket 32585
     1215     */
     1216    public function test_wp_insert_post_author_null() {
     1217        $post_id = $this->factory->post->create( array( 'post_author' => null ) );
     1218
     1219        $this->assertEquals( $this->author_id, get_post( $post_id )->post_author );
     1220    }
    12031221}
Note: See TracChangeset for help on using the changeset viewer.