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. *