Customize: Align behavior of `WP_Customize_Manager::save_changeset_post()` with `wp_insert_post()` by setting status to `future` if supplied status is `publish` but date is future.

Props dlh.
Fixes #41336.


git-svn-id: https://develop.svn.wordpress.org/trunk@41372 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2017-09-11 17:49:58 +00:00
parent 34df35a414
commit 4fbb54ca8c
2 changed files with 22 additions and 0 deletions

View File

@ -2272,6 +2272,10 @@ final class WP_Customize_Manager {
} }
} }
if ( ! empty( $is_future_dated ) && 'publish' === $args['status'] ) {
$args['status'] = 'future';
}
// The request was made via wp.customize.previewer.save(). // The request was made via wp.customize.previewer.save().
$update_transactionally = (bool) $args['status']; $update_transactionally = (bool) $args['status'];
$allow_revision = (bool) $args['status']; $allow_revision = (bool) $args['status'];

View File

@ -1412,6 +1412,24 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$this->assertEquals( $new_sidebar_1, $updated_sidebars_widgets['sidebar-1'] ); $this->assertEquals( $new_sidebar_1, $updated_sidebars_widgets['sidebar-1'] );
} }
/**
* Ensure that saving a changeset with a publish status but future date will change the status to future, to align with behavior in wp_insert_post().
*
* @ticket 41336
* @covers WP_Customize_Manager::save_changeset_post
*/
function test_publish_changeset_with_future_status_when_future_date() {
$wp_customize = $this->create_test_manager( wp_generate_uuid4() );
$wp_customize->save_changeset_post( array(
'date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( '+1 day' ) ),
'status' => 'publish',
'title' => 'Foo',
) );
$this->assertSame( 'future', get_post_status( $wp_customize->changeset_post_id() ) );
}
/** /**
* Ensure that save_changeset_post method bails updating an underlying changeset which is invalid. * Ensure that save_changeset_post method bails updating an underlying changeset which is invalid.
* *