Make WordPress Core

Changeset 41187


Ignore:
Timestamp:
07/30/2017 02:40:42 PM (8 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

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

    r40989 r41187  
    565565        }
    566566
     567        if ( isset( $post_data['post_format'] ) ) {
     568            set_post_format( $post_ID, $post_data['post_format'] );
     569            unset( $post_data['tax_input']['post_format'] );
     570        }
     571
    567572        $updated[] = wp_update_post( $post_data );
    568573
     
    573578                unstick_post( $post_ID );
    574579        }
    575 
    576         if ( isset( $post_data['post_format'] ) )
    577             set_post_format( $post_ID, $post_data['post_format'] );
    578580    }
    579581
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r39062 r41187  
    208208     * @ticket 27792
    209209     */
    210     function test_bulk_edit_posts_stomping() {
     210    public function test_bulk_edit_posts_stomping() {
    211211        wp_set_current_user( self::$admin_id );
    212212
     
    243243        $this->assertEquals( 'closed', $post->comment_status );
    244244        $this->assertEquals( 'closed', $post->ping_status );
     245    }
     246
     247    /**
     248     * @ticket 41396
     249     */
     250    public function test_bulk_edit_posts_should_set_post_format_before_wp_update_post_runs() {
     251        wp_set_current_user( self::$admin_id );
     252
     253        $request = array(
     254            'post_format' => 'aside',
     255            '_status'     => -1,
     256            'post'        => array( self::$post_id ),
     257        );
     258
     259        add_action( 'save_post', array( $this, 'check_post_format' ) );
     260
     261        bulk_edit_posts( $request );
     262
     263        remove_action( 'save_post', array( $this, 'check_post_format' ) );
     264    }
     265
     266    public function check_post_format( $post_id ) {
     267        if ( self::$post_id === $post_id ) {
     268            $this->assertEquals( 'aside', get_post_format( $post_id ) );
     269        }
    245270    }
    246271
Note: See TracChangeset for help on using the changeset viewer.