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. git-svn-id: https://develop.svn.wordpress.org/trunk@40041 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4b22b97004
commit
647f06c2c1
@ -2494,6 +2494,14 @@ final class WP_Customize_Manager {
|
||||
} elseif ( $args['date_gmt'] ) {
|
||||
$post_array['post_date_gmt'] = $args['date_gmt'];
|
||||
$post_array['post_date'] = get_date_from_gmt( $args['date_gmt'] );
|
||||
} elseif ( $changeset_post_id && 'auto-draft' === get_post_status( $changeset_post_id ) ) {
|
||||
/*
|
||||
* Keep bumping the date for the auto-draft whenever it is modified;
|
||||
* this extends its life, preserving it from garbage-collection via
|
||||
* wp_delete_auto_drafts().
|
||||
*/
|
||||
$post_array['post_date'] = current_time( 'mysql' );
|
||||
$post_array['post_date_gmt'] = '';
|
||||
}
|
||||
|
||||
$this->store_changeset_revision = $allow_revision;
|
||||
|
@ -1104,6 +1104,43 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
return $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that updating an auto-draft changeset bumps its post_date to keep it from getting garbage collected by wp_delete_auto_drafts().
|
||||
*
|
||||
* @ticket 31089
|
||||
* @see wp_delete_auto_drafts()
|
||||
* @covers WP_Customize_Manager::save_changeset_post()
|
||||
*/
|
||||
function test_save_changeset_post_dumping_auto_draft_date() {
|
||||
global $wp_customize;
|
||||
wp_set_current_user( self::$admin_user_id );
|
||||
|
||||
$uuid = wp_generate_uuid4();
|
||||
$changeset_post_id = wp_insert_post( array(
|
||||
'post_type' => 'customize_changeset',
|
||||
'post_content' => '{}',
|
||||
'post_name' => $uuid,
|
||||
'post_status' => 'auto-draft',
|
||||
'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-3 days' ) ),
|
||||
) );
|
||||
|
||||
$post = get_post( $changeset_post_id );
|
||||
$original_post_date = $post->post_date;
|
||||
|
||||
$wp_customize = $this->create_test_manager( $uuid );
|
||||
$wp_customize->save_changeset_post( array(
|
||||
'status' => 'auto-draft',
|
||||
'data' => array(
|
||||
'blogname' => array(
|
||||
'value' => 'Admin 1 Title',
|
||||
),
|
||||
),
|
||||
) );
|
||||
|
||||
$post = get_post( $changeset_post_id );
|
||||
$this->assertNotEquals( $post->post_date, $original_post_date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writing changesets when user supplies unchanged values.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user