Make WordPress Core

Changeset 40099 for branches/4.7


Ignore:
Timestamp:
02/21/2017 07:02:14 AM (8 years ago)
Author:
dd32
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.

Props westonruter.
Merges [40041] to the 4.7 branch.
See #30937.
Fixes #39713.

Location:
branches/4.7
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/class-wp-customize-manager.php

    r40098 r40099  
    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
  • branches/4.7/tests/phpunit/tests/customize/manager.php

    r40098 r40099  
    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.