Make WordPress Core

Ticket #31635: 31635-2.patch

File 31635-2.patch, 3.2 KB (added by cadic, 2 years ago)

Patch including both future and draft post statuses

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

    diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php
    index 824b9694507..bdb07604a4e 100644
    a b function bulk_edit_posts( $post_data = null ) { 
    664664                // Prevent wp_insert_post() from overwriting post format with the old data.
    665665                unset( $post_data['tax_input']['post_format'] );
    666666
     667                // Reset post date of scheduled post to be published.
     668                if ( in_array( $post->post_status, array( 'future', 'draft' ), true ) && 'publish' === $post_data['post_status'] ) {
     669                        $post_data['post_date']     = current_time( 'mysql' );
     670                        $post_data['post_date_gmt'] = '';
     671                }
     672
    667673                $post_id = wp_update_post( $post_data );
    668674                update_post_meta( $post_id, '_edit_last', get_current_user_id() );
    669675                $updated[] = $post_id;
  • tests/phpunit/tests/admin/includesPost.php

    diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php
    index 799d927dfa9..41d56f841f2 100644
    a b public function test_bulk_edit_posts_should_preserve_post_format_when_unchanged( 
    293293                $this->assertFalse( get_post_format( $post_ids[2] ) );
    294294        }
    295295
     296        /**
     297         * @ticket 31635
     298         */
     299        public function test_bulk_edit_posts_should_publish_scheduled_post() {
     300                wp_set_current_user( self::$admin_id );
     301
     302                $post = self::factory()->post->create(
     303                        array(
     304                                'post_author'    => self::$author_ids[0],
     305                                'comment_status' => 'closed',
     306                                'ping_status'    => 'closed',
     307                                'post_status'    => 'future',
     308                                'post_date'      => gmdate( 'Y-m-d H:i:s', strtotime( '+1 month' ) ),
     309                        )
     310                );
     311
     312                $request = array(
     313                        'post_type'      => 'post',
     314                        'post_author'    => -1,
     315                        'ping_status'    => -1,
     316                        'comment_status' => -1,
     317                        '_status'        => 'publish',
     318                        'post'           => array( $post ),
     319                );
     320
     321                bulk_edit_posts( $request );
     322
     323                $this->assertSame( 'publish', get_post_status( $post ) );
     324                $this->assertLessThanOrEqual( gmdate( 'Y-m-d H:i:s' ), get_post_time( 'Y-m-d H:i:s', false, $post ) );
     325        }
     326
     327        /**
     328         * @ticket 31635
     329         */
     330        public function test_bulk_edit_posts_should_publish_draft_immediately() {
     331                wp_set_current_user( self::$admin_id );
     332
     333                // Create draft last edited a month ago
     334                $post = self::factory()->post->create(
     335                        array(
     336                                'post_author'    => self::$author_ids[0],
     337                                'comment_status' => 'closed',
     338                                'ping_status'    => 'closed',
     339                                'post_status'    => 'draft',
     340                                'post_date'      => gmdate( 'Y-m-d H:i:s', strtotime( '-1 month' ) ),
     341                        )
     342                );
     343
     344                $request = array(
     345                        'post_type'      => 'post',
     346                        'post_author'    => -1,
     347                        'ping_status'    => -1,
     348                        'comment_status' => -1,
     349                        '_status'        => 'publish',
     350                        'post'           => array( $post ),
     351                );
     352
     353                bulk_edit_posts( $request );
     354
     355                $this->assertSame( 'publish', get_post_status( $post ) );
     356
     357                // Expect to be published within the last minute (to consider slow testing environment).
     358                $minute_before = gmdate( 'Y-m-d H:i:s', strtotime( '-1 minute' ) );
     359                $this->assertGreaterThanOrEqual( $minute_before, get_post_time( 'Y-m-d H:i:s', false, $post ) );
     360                $this->assertLessThanOrEqual( gmdate( 'Y-m-d H:i:s' ), get_post_time( 'Y-m-d H:i:s', false, $post ) );
     361        }
     362
    296363        /**
    297364         * @ticket 41396
    298365         */