Make WordPress Core

Changeset 28113 for trunk


Ignore:
Timestamp:
04/14/2014 07:47:10 AM (12 years ago)
Author:
nacin
Message:

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

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

props dd32, DrewAPicture.
fixes #27792.

Location:
trunk
Files:
2 edited

Legend:

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

    r27990 r28113  
    434434
    435435        $updated = $skipped = $locked = array();
     436        $shared_post_data = $post_data;
     437
    436438        foreach ( $post_IDs as $post_ID ) {
     439                // Start with fresh post data with each iteration.
     440                $post_data = $shared_post_data;
     441
    437442                $post_type_object = get_post_type_object( get_post_type( $post_ID ) );
    438443
     
    483488                $post_data['post_ID'] = $post_ID;
    484489
    485                 $translated_post_data = _wp_translate_postdata( true, $post_data );
    486                 if ( is_wp_error( $translated_post_data ) ) {
     490                $post_data = _wp_translate_postdata( true, $post_data );
     491                if ( is_wp_error( $post_data ) ) {
    487492                        $skipped[] = $post_ID;
    488493                        continue;
    489494                }
    490495
    491                 $updated[] = wp_update_post( $translated_post_data );
     496                $updated[] = wp_update_post( $post_data );
    492497
    493498                if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r27405 r28113  
    55 */
    66class Tests_Admin_includesPost extends WP_UnitTestCase {
     7
     8        function tearDown() {
     9                wp_set_current_user( 0 );
     10                parent::tearDown();
     11        }
    712
    813        function test__wp_translate_postdata_cap_checks_contributor() {
     
    5762                $this->assertEquals( 'edit_others_posts', $_results->get_error_code() );
    5863                $this->assertEquals( 'You are not allowed to edit posts as this user.', $_results->get_error_message() );
    59 
    60                 wp_set_current_user( 0 );
    6164        }
    6265
     
    112115                $this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
    113116                $this->assertEquals( 'draft', $_results['post_status'] );
    114 
    115                 wp_set_current_user( 0 );
    116117        }
    117118
     
    134135                edit_post( $post_data );
    135136                $this->assertEquals( 'draft', get_post( $post->ID )->post_status );
    136                 wp_set_current_user( 0 );
     137        }
     138
     139        /**
     140         * @ticket 27792
     141         */
     142        function test_bulk_edit_posts_stomping() {
     143                $admin = $this->factory->user->create( array( 'role' => 'administrator' ) );
     144                $users = $this->factory->user->create_many( 2, array( 'role' => 'author' ) );
     145                wp_set_current_user( $admin );
     146
     147                $post1 = $this->factory->post->create( array(
     148                        'post_author'    => $users[0],
     149                        'comment_status' => 'open',
     150                        'ping_status'    => 'open',
     151                        'post_status'    => 'publish',
     152                ) );
     153
     154                $post2 = $this->factory->post->create( array(
     155                        'post_author'    => $users[1],
     156                        'comment_status' => 'closed',
     157                        'ping_status'    => 'closed',
     158                        'post_status'    => 'draft',
     159                ) );
     160
     161                $request = array(
     162                        'post_type'        => 'post',
     163                        'post_author'      => -1,
     164                        'ping_status'      => -1,
     165                        'comment_status'   => -1,
     166                        '_status'          => -1,
     167                        'post'             => array( $post1, $post2 ),
     168                );
     169
     170                $done = bulk_edit_posts( $request );
     171
     172                $post = get_post( $post2 );
     173
     174                // Check that the first post's values don't stomp the second post.
     175                $this->assertEquals( 'draft', $post->post_status );
     176                $this->assertEquals( $users[1], $post->post_author );
     177                $this->assertEquals( 'closed', $post->comment_status );
     178                $this->assertEquals( 'closed', $post->ping_status );
    137179        }
    138180
Note: See TracChangeset for help on using the changeset viewer.