From ddc6fafd06ebebab0bc319886d92851f3396f72d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 30 Jul 2017 14:40:42 +0000 Subject: [PATCH] Post Formats: In `bulk_edit_posts()`, set post format before the post is updated, for consistency with `edit_post()`. This makes sure that plugins hooked to `save_post` get the right post format. Props Chouby, SergeyBiryukov. Fixes #41396. git-svn-id: https://develop.svn.wordpress.org/trunk@41187 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/post.php | 8 ++++--- tests/phpunit/tests/admin/includesPost.php | 27 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index bc3ee7849d..febe05afaf 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -564,6 +564,11 @@ function bulk_edit_posts( $post_data = null ) { continue; } + if ( isset( $post_data['post_format'] ) ) { + set_post_format( $post_ID, $post_data['post_format'] ); + unset( $post_data['tax_input']['post_format'] ); + } + $updated[] = wp_update_post( $post_data ); if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { @@ -572,9 +577,6 @@ function bulk_edit_posts( $post_data = null ) { else unstick_post( $post_ID ); } - - if ( isset( $post_data['post_format'] ) ) - set_post_format( $post_ID, $post_data['post_format'] ); } return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked ); diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 4dcd59b64a..f2df065e49 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -207,7 +207,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { /** * @ticket 27792 */ - function test_bulk_edit_posts_stomping() { + public function test_bulk_edit_posts_stomping() { wp_set_current_user( self::$admin_id ); $post1 = self::factory()->post->create( array( @@ -244,6 +244,31 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $this->assertEquals( 'closed', $post->ping_status ); } + /** + * @ticket 41396 + */ + public function test_bulk_edit_posts_should_set_post_format_before_wp_update_post_runs() { + wp_set_current_user( self::$admin_id ); + + $request = array( + 'post_format' => 'aside', + '_status' => -1, + 'post' => array( self::$post_id ), + ); + + add_action( 'save_post', array( $this, 'check_post_format' ) ); + + bulk_edit_posts( $request ); + + remove_action( 'save_post', array( $this, 'check_post_format' ) ); + } + + public function check_post_format( $post_id ) { + if ( self::$post_id === $post_id ) { + $this->assertEquals( 'aside', get_post_format( $post_id ) ); + } + } + /** * @ticket 38293 */