Make WordPress Core

Changeset 44670


Ignore:
Timestamp:
01/21/2019 06:04:55 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Post Formats: Prevent Bulk Edit from unintentionally changing post format to Standard even if set to "No change".

Correct the logic in [41187].

Props birgire, mukesh27, lanche86.
Fixes #44914. See #41396.

Location:
trunk
Files:
2 edited

Legend:

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

    r44574 r44670  
    611611        if ( isset( $shared_post_data['post_format'] ) ) {
    612612            set_post_format( $post_ID, $shared_post_data['post_format'] );
    613             unset( $post_data['tax_input']['post_format'] );
    614         }
     613        }
     614
     615        // Prevent wp_insert_post() from overwriting post format with the old data.
     616        unset( $post_data['tax_input']['post_format'] );
    615617
    616618        $updated[] = wp_update_post( $post_data );
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r44153 r44670  
    256256
    257257    /**
     258     * The bulk_edit_posts() function should preserve the post format
     259     * when it's unchanged.
     260     *
     261     * @ticket 44914
     262     */
     263    public function test_bulk_edit_posts_should_preserve_post_format_when_unchanged() {
     264        wp_set_current_user( self::$admin_id );
     265
     266        $post_ids = self::factory()->post->create_many( 3 );
     267
     268        set_post_format( $post_ids[0], 'image' );
     269        set_post_format( $post_ids[1], 'aside' );
     270
     271        $request = array(
     272            'post_format'    => -1, // Don't change the post format.
     273            '_status'        => -1,
     274            'post'           => $post_ids,
     275        );
     276
     277        bulk_edit_posts( $request );
     278
     279        $terms1 = get_the_terms( $post_ids[0], 'post_format' );
     280        $terms2 = get_the_terms( $post_ids[1], 'post_format' );
     281        $terms3 = get_the_terms( $post_ids[2], 'post_format' );
     282
     283        $this->assertSame( 'post-format-image', $terms1[0]->slug );
     284        $this->assertSame( 'post-format-aside', $terms2[0]->slug );
     285        $this->assertFalse( $terms3 );
     286
     287        $this->assertSame( 'image', get_post_format( $post_ids[0] ) );
     288        $this->assertSame( 'aside', get_post_format( $post_ids[1] ) );
     289        $this->assertFalse( get_post_format( $post_ids[2] ) );
     290    }
     291
     292    /**
    258293     * @ticket 41396
    259294     */
Note: See TracChangeset for help on using the changeset viewer.