From 4fbb54ca8ce055ca80ffc774d585073deac4de08 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 11 Sep 2017 17:49:58 +0000 Subject: [PATCH] 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 --- src/wp-includes/class-wp-customize-manager.php | 4 ++++ tests/phpunit/tests/customize/manager.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index 31d9d355d3..1bb832396a 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -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(). $update_transactionally = (bool) $args['status']; $allow_revision = (bool) $args['status']; diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php index 559371d58c..1955a1cd74 100644 --- a/tests/phpunit/tests/customize/manager.php +++ b/tests/phpunit/tests/customize/manager.php @@ -1412,6 +1412,24 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { $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. *