diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 108c848010..bd13630062 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -1152,7 +1152,7 @@ function get_sample_permalink($id, $title = null, $name = null) { $original_name = $post->post_name; // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published. - if ( in_array( $post->post_status, array( 'draft', 'pending' ) ) ) { + if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) { $post->post_status = 'publish'; $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID); } diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index f94605af0a..4ba3de71df 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -178,4 +178,26 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $this->assertEquals( 'closed', $post->ping_status ); } -} \ No newline at end of file + /** + * @ticket 30910 + */ + public function test_get_sample_permalink_should_return_pretty_permalink_for_posts_with_post_status_future() { + global $wp_rewrite; + + $old_permalink_structure = get_option( 'permalink_structure' ); + $permalink_structure = '%postname%'; + $wp_rewrite->set_permalink_structure( "/$permalink_structure/" ); + flush_rewrite_rules(); + + $future_date = date( 'Y-m-d H:i:s', time() + 100 ); + $p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) ); + + $found = get_sample_permalink( $p ); + $expected = trailingslashit( home_url( $permalink_structure ) ); + + $this->assertSame( $expected, $found[0] ); + + $wp_rewrite->set_permalink_structure( $old_permalink_structure ); + flush_rewrite_rules(); + } +}