mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@34085 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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'] : '';
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user