Skip to content

Posts: Display Scheduled state for future-dated private posts #9389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/wp-admin/includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down
48 changes: 48 additions & 0 deletions tests/phpunit/tests/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
Loading