From f05f38063821e1920b72a733ca05bedfa79dc1b0 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 2 Feb 2015 16:49:23 +0000 Subject: [PATCH] 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 --- src/wp-admin/includes/post.php | 2 +- tests/phpunit/tests/admin/includesPost.php | 24 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) 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(); + } +}