In `get_sample_permalink()`, override 'future' status before generating permalink.

In [31114], `get_permalink()` was modified to prevent pretty permalinks from
being generated for posts with the 'future' post status. This inadvertently
broke the pretty permalink preview for scheduled posts. The fix is to include
the 'future' status in the list of statuses that `get_sample_permalink()` fakes
as 'publish' before it fetches a permalink.

Props DrewAPicture.
Fixes #30910.

git-svn-id: https://develop.svn.wordpress.org/trunk@31323 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2015-02-02 16:49:23 +00:00
parent c61dff8c21
commit f05f380638
2 changed files with 24 additions and 2 deletions

View File

@ -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);
}

View File

@ -178,4 +178,26 @@ class Tests_Admin_includesPost extends WP_UnitTestCase {
$this->assertEquals( 'closed', $post->ping_status );
}
/**
* @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();
}
}