From a14b99960511725b55e927671165645e54dffd04 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 5 Mar 2014 06:25:31 +0000 Subject: [PATCH] Always convert auto-drafts to drafts in edit_draft() and _wp_translate_postdata(). This regressed due to refactoring in [26995]. This commit fixes Quick Draft. see #25272. git-svn-id: https://develop.svn.wordpress.org/trunk@27405 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/post.php | 8 +++++--- tests/phpunit/tests/admin/includesPost.php | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 9754c3dbf8..806c8b3f00 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -83,8 +83,9 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); // No longer an auto-draft - if ( 'auto-draft' == $post_data['post_status'] ) + if ( 'auto-draft' === $post_data['post_status'] ) { $post_data['post_status'] = 'draft'; + } } // What to do based on which button they pressed @@ -113,8 +114,9 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { if ( ! in_array( $previous_status, $published_statuses ) || !current_user_can( 'edit_post', $post_id ) ) $post_data['post_status'] = 'pending'; - if ( ! isset($post_data['post_status']) ) - $post_data['post_status'] = $previous_status; + if ( ! isset( $post_data['post_status'] ) ) { + $post_data['post_status'] = 'auto-draft' === $previous_status ? 'draft' : $previous_status; + } if (!isset( $post_data['comment_status'] )) $post_data['comment_status'] = 'closed'; diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index e359830ca1..4358ffb06f 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -114,4 +114,26 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { wp_set_current_user( 0 ); } + + /** + * edit_post() should convert an existing auto-draft to a draft. + * + * @ticket 25272 + */ + function test_edit_post_auto_draft() { + $user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); + wp_set_current_user( $user_id ); + $post = $this->factory->post->create_and_get( array( 'post_status' => 'auto-draft' ) ); + $this->assertEquals( 'auto-draft', $post->post_status ); + $post_data = array( + 'post_title' => 'Post title', + 'content' => 'Post content', + 'post_type' => 'post', + 'post_ID' => $post->ID, + ); + edit_post( $post_data ); + $this->assertEquals( 'draft', get_post( $post->ID )->post_status ); + wp_set_current_user( 0 ); + } + } \ No newline at end of file