diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php
index cf8c8e9f01..e1a1d3fc60 100644
--- a/src/wp-admin/includes/post.php
+++ b/src/wp-admin/includes/post.php
@@ -1294,6 +1294,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
$post_name_html = '' . $post_name_abridged . '';
$display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, urldecode( $permalink ) );
+ $pretty_permalink = str_replace( array( '%pagename%', '%postname%' ), $post_name, urldecode( $permalink ) );
$return = '' . __( 'Permalink:' ) . "\n";
$return .= '' . $display_link . "\n";
@@ -1309,7 +1310,11 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
$preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
$return .= "$view_post\n";
} else {
- $return .= "$view_post\n";
+ if ( empty( $pretty_permalink ) ) {
+ $pretty_permalink = $permalink;
+ }
+
+ $return .= "$view_post\n";
}
}
diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php
index 0388a82a09..5d2623a065 100644
--- a/tests/phpunit/tests/admin/includesPost.php
+++ b/tests/phpunit/tests/admin/includesPost.php
@@ -269,4 +269,48 @@ class Tests_Admin_includesPost extends WP_UnitTestCase {
$wp_rewrite->set_permalink_structure( $old_permalink_structure );
flush_rewrite_rules();
}
+
+ /**
+ * @ticket 30910
+ */
+ public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_button_when_pretty_permalinks_are_disabled() {
+ global $wp_rewrite;
+ $old_permalink_structure = get_option( 'permalink_structure' );
+ $wp_rewrite->set_permalink_structure( '' );
+ flush_rewrite_rules();
+
+ wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
+
+ $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_html( $p );
+ $this->assertContains( "span id='view-post-btn'>set_permalink_structure( $old_permalink_structure );
+ flush_rewrite_rules();
+ }
+
+ /**
+ * @ticket 30910
+ */
+ public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_post_button_when_pretty_permalinks_are_enabled() {
+ global $wp_rewrite;
+ $old_permalink_structure = get_option( 'permalink_structure' );
+ $permalink_structure = '%postname%';
+ $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
+ flush_rewrite_rules();
+
+ wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
+
+ $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_html( $p );
+ $post = get_post( $p );
+ $this->assertContains( "span id='view-post-btn'>post_name . "/'", $found );
+
+ $wp_rewrite->set_permalink_structure( $old_permalink_structure );
+ flush_rewrite_rules();
+ }
}