Make WordPress Core

Changeset 28115 for branches/3.7


Ignore:
Timestamp:
04/14/2014 08:12:42 AM (11 years ago)
Author:
nacin
Message:

Avoid stomping of bulk postdata inside the bulk_edit_posts() loop.

Merges [28113] to the 3.7 branch.

Reverts [27992] which did not fix it for authors and comment/ping status.

props dd32, DrewAPicture.
fixes #27792.

Location:
branches/3.7
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

  • branches/3.7/src

  • branches/3.7/src/wp-admin/includes/post.php

    r28074 r28115  
    412412
    413413    $updated = $skipped = $locked = array();
     414    $shared_post_data = $post_data;
     415
    414416    foreach ( $post_IDs as $post_ID ) {
     417        // Start with fresh post data with each iteration.
     418        $post_data = $shared_post_data;
     419
    415420        $post_type_object = get_post_type_object( get_post_type( $post_ID ) );
    416421
     
    461466        $post_data['post_ID'] = $post_ID;
    462467
    463         $translated_post_data = _wp_translate_postdata( true, $post_data );
    464         if ( is_wp_error( $translated_post_data ) ) {
     468        $post_data = _wp_translate_postdata( true, $post_data );
     469        if ( is_wp_error( $post_data ) ) {
    465470            $skipped[] = $post_ID;
    466471            continue;
    467472        }
    468473
    469         $updated[] = wp_update_post( $translated_post_data );
     474        $updated[] = wp_update_post( $post_data );
    470475
    471476        if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
  • branches/3.7/tests/phpunit/tests/admin/includesPost.php

    r28074 r28115  
    135135        $this->assertEquals( 'draft', $updated->post_status );
    136136    }
     137
     138    /**
     139     * @ticket 27792
     140     */
     141    function test_bulk_edit_posts_stomping() {
     142        $admin = $this->factory->user->create( array( 'role' => 'administrator' ) );
     143        $users = $this->factory->user->create_many( 2, array( 'role' => 'author' ) );
     144        wp_set_current_user( $admin );
     145
     146        $post1 = $this->factory->post->create( array(
     147            'post_author'    => $users[0],
     148            'comment_status' => 'open',
     149            'ping_status'    => 'open',
     150            'post_status'    => 'publish',
     151        ) );
     152
     153        $post2 = $this->factory->post->create( array(
     154            'post_author'    => $users[1],
     155            'comment_status' => 'closed',
     156            'ping_status'    => 'closed',
     157            'post_status'    => 'draft',
     158        ) );
     159
     160        $request = array(
     161            'post_type'        => 'post',
     162            'post_author'      => -1,
     163            'ping_status'      => -1,
     164            'comment_status'   => -1,
     165            '_status'          => -1,
     166            'post'             => array( $post1, $post2 ),
     167        );
     168
     169        $done = bulk_edit_posts( $request );
     170
     171        $post = get_post( $post2 );
     172
     173        // Check that the first post's values don't stomp the second post.
     174        $this->assertEquals( 'draft', $post->post_status );
     175        $this->assertEquals( $users[1], $post->post_author );
     176        $this->assertEquals( 'closed', $post->comment_status );
     177        $this->assertEquals( 'closed', $post->ping_status );
     178    }
     179
    137180}
Note: See TracChangeset for help on using the changeset viewer.