diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index 43e3442b001d5..1c07aece5eb98 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -2295,6 +2295,9 @@ function get_post_states( $post ) { if ( 'private' === $post->post_status && 'private' !== $post_status ) { $post_states['private'] = _x( 'Private', 'post status' ); } + if ( 'private' === $post->post_status && strtotime( $post->post_date_gmt ) > time() ) { + $post_states['scheduled'] = _x( 'Scheduled', 'post status' ); + } if ( 'draft' === $post->post_status ) { if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 36c337939eaca..79dbc30f8f794 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -759,4 +759,52 @@ public function test_use_block_editor_for_post() { $this->assertTrue( use_block_editor_for_post( $restless_post_id ) ); remove_filter( 'use_block_editor_for_post', '__return_true' ); } + + /** + * Tests that a private post with a future date returns both 'Private' and 'Scheduled' states. + * + * @ticket 18264 + */ + public function test_get_post_states_for_future_dated_private_post() { + $future_date = gmdate( 'Y-m-d H:i:s', time() + HOUR_IN_SECONDS ); + + $post = self::factory()->post->create_and_get( + array( + 'post_status' => 'private', + 'post_date' => get_date_from_gmt( $future_date ), + 'post_date_gmt' => $future_date, + ) + ); + + $this->assertSame( + array( + 'private' => 'Private', + 'scheduled' => 'Scheduled', + ), + get_post_states( $post ) + ); + } + + /** + * Tests that the _post_states() function correctly renders the HTML + * for a future-dated private post. + * + * @ticket 18264 + */ + public function test_post_states_renders_correctly_for_future_private_post() { + $future_date = gmdate( 'Y-m-d H:i:s', time() + HOUR_IN_SECONDS ); + + $post = self::factory()->post->create_and_get( + array( + 'post_status' => 'private', + 'post_date' => get_date_from_gmt( $future_date ), + 'post_date_gmt' => $future_date, + ) + ); + + $rendered_states = _post_states( $post, false ); + + $this->assertStringContainsString( 'Private', $rendered_states ); + $this->assertStringContainsString( 'Scheduled', $rendered_states ); + } }