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. git-svn-id: https://develop.svn.wordpress.org/trunk@44670 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
95c496b39e
commit
8fe01c0621
|
@ -610,9 +610,11 @@ function bulk_edit_posts( $post_data = null ) {
|
|||
|
||||
if ( isset( $shared_post_data['post_format'] ) ) {
|
||||
set_post_format( $post_ID, $shared_post_data['post_format'] );
|
||||
unset( $post_data['tax_input']['post_format'] );
|
||||
}
|
||||
|
||||
// Prevent wp_insert_post() from overwriting post format with the old data.
|
||||
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 ) ) {
|
||||
|
|
|
@ -254,6 +254,41 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
|
|||
$this->assertEquals( 'closed', $post->ping_status );
|
||||
}
|
||||
|
||||
/**
|
||||
* The bulk_edit_posts() function should preserve the post format
|
||||
* when it's unchanged.
|
||||
*
|
||||
* @ticket 44914
|
||||
*/
|
||||
public function test_bulk_edit_posts_should_preserve_post_format_when_unchanged() {
|
||||
wp_set_current_user( self::$admin_id );
|
||||
|
||||
$post_ids = self::factory()->post->create_many( 3 );
|
||||
|
||||
set_post_format( $post_ids[0], 'image' );
|
||||
set_post_format( $post_ids[1], 'aside' );
|
||||
|
||||
$request = array(
|
||||
'post_format' => -1, // Don't change the post format.
|
||||
'_status' => -1,
|
||||
'post' => $post_ids,
|
||||
);
|
||||
|
||||
bulk_edit_posts( $request );
|
||||
|
||||
$terms1 = get_the_terms( $post_ids[0], 'post_format' );
|
||||
$terms2 = get_the_terms( $post_ids[1], 'post_format' );
|
||||
$terms3 = get_the_terms( $post_ids[2], 'post_format' );
|
||||
|
||||
$this->assertSame( 'post-format-image', $terms1[0]->slug );
|
||||
$this->assertSame( 'post-format-aside', $terms2[0]->slug );
|
||||
$this->assertFalse( $terms3 );
|
||||
|
||||
$this->assertSame( 'image', get_post_format( $post_ids[0] ) );
|
||||
$this->assertSame( 'aside', get_post_format( $post_ids[1] ) );
|
||||
$this->assertFalse( get_post_format( $post_ids[2] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41396
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue