Make WordPress Core

Changeset 40041


Ignore:
Timestamp:
02/05/2017 06:38:57 AM (7 years ago)
Author:
westonruter
Message:

Customize: Extend auto-draft life of a customize_changeset post whenever modified.

Keep bumping the date for the auto-draft to preserve it from garbage-collection via wp_delete_auto_drafts() after 7 days.

See #30937.
Fixes #39713.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r39951 r40041  
    24952495            $post_array['post_date_gmt'] = $args['date_gmt'];
    24962496            $post_array['post_date'] = get_date_from_gmt( $args['date_gmt'] );
     2497        } elseif ( $changeset_post_id && 'auto-draft' === get_post_status( $changeset_post_id ) ) {
     2498            /*
     2499             * Keep bumping the date for the auto-draft whenever it is modified;
     2500             * this extends its life, preserving it from garbage-collection via
     2501             * wp_delete_auto_drafts().
     2502             */
     2503            $post_array['post_date'] = current_time( 'mysql' );
     2504            $post_array['post_date_gmt'] = '';
    24972505        }
    24982506
  • trunk/tests/phpunit/tests/customize/manager.php

    r39924 r40041  
    11061106
    11071107    /**
     1108     * Test that updating an auto-draft changeset bumps its post_date to keep it from getting garbage collected by wp_delete_auto_drafts().
     1109     *
     1110     * @ticket 31089
     1111     * @see wp_delete_auto_drafts()
     1112     * @covers WP_Customize_Manager::save_changeset_post()
     1113     */
     1114    function test_save_changeset_post_dumping_auto_draft_date() {
     1115        global $wp_customize;
     1116        wp_set_current_user( self::$admin_user_id );
     1117
     1118        $uuid = wp_generate_uuid4();
     1119        $changeset_post_id = wp_insert_post( array(
     1120            'post_type' => 'customize_changeset',
     1121            'post_content' => '{}',
     1122            'post_name' => $uuid,
     1123            'post_status' => 'auto-draft',
     1124            'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-3 days' ) ),
     1125        ) );
     1126
     1127        $post = get_post( $changeset_post_id );
     1128        $original_post_date = $post->post_date;
     1129
     1130        $wp_customize = $this->create_test_manager( $uuid );
     1131        $wp_customize->save_changeset_post( array(
     1132            'status' => 'auto-draft',
     1133            'data' => array(
     1134                'blogname' => array(
     1135                    'value' => 'Admin 1 Title',
     1136                ),
     1137            ),
     1138        ) );
     1139
     1140        $post = get_post( $changeset_post_id );
     1141        $this->assertNotEquals( $post->post_date, $original_post_date );
     1142    }
     1143
     1144    /**
    11081145     * Test writing changesets when user supplies unchanged values.
    11091146     *
Note: See TracChangeset for help on using the changeset viewer.