diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 37366b3d14..2a41442534 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -1302,7 +1302,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { $view_link = get_permalink( $post ); } else { // Allow non-published (private, future) to be viewed at a pretty permalink. - $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, urldecode( $permalink ) ); + $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink ); } } } @@ -1312,7 +1312,8 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { $return = '' . __( 'Permalink:' ) . "\n"; if ( false !== $view_link ) { - $return .= '' . $view_link . "\n"; + $display_link = urldecode( $view_link ); + $return .= '' . $display_link . "\n"; } else { $return .= '' . $permalink . "\n"; } diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 89803cc150..5500899864 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -280,6 +280,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $found = get_sample_permalink_html( $p ); $this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found ); + $this->assertContains( '>' . get_option( 'home' ) . '/?p=' . $p . '<', $found ); } /** @@ -292,11 +293,33 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { wp_set_current_user( self::$admin_id ); $future_date = date( 'Y-m-d H:i:s', time() + 100 ); - $p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) ); + $p = self::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( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found ); + $this->assertContains( '>' . urldecode( $post->post_name ) . '<', $found ); + } + + /** + * @ticket 35980 + */ + public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_attachment_link_when_pretty_permalinks_are_enabled() { + $this->set_permalink_structure( '/%postname%/' ); + + wp_set_current_user( self::$admin_id ); + + $p = self::factory()->attachment->create_object( 'صورة.jpg', 0, array( + 'post_mime_type' => 'image/jpeg', + 'post_type' => 'attachment', + 'post_title' => 'صورة', + 'post_status' => 'inherit', + ) ); + + $found = get_sample_permalink_html( $p ); + $post = get_post( $p ); + $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found ); + $this->assertContains( '>' . urldecode( get_permalink( $post ) ) . '<', $found ); } /** @@ -309,26 +332,28 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { wp_set_current_user( self::$admin_id ); // Published posts should use published permalink - $p = self::factory()->post->create( array( 'post_status' => 'publish', 'post_name' => 'foo' ) ); + $p = self::factory()->post->create( array( 'post_status' => 'publish', 'post_name' => 'foo-صورة' ) ); - $found = get_sample_permalink_html( $p, null, 'new_slug' ); + $found = get_sample_permalink_html( $p, null, 'new_slug-صورة' ); $post = get_post( $p ); $message = 'Published post'; $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found, $message ); + $this->assertContains( '>new_slug-صورة<', $found, $message ); // Scheduled posts should use published permalink $future_date = date( 'Y-m-d H:i:s', time() + 100 ); - $p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'bar', 'post_date' => $future_date ) ); + $p = self::factory()->post->create( array( 'post_status' => 'future', 'post_name' => 'bar-صورة', 'post_date' => $future_date ) ); - $found = get_sample_permalink_html( $p, null, 'new_slug' ); + $found = get_sample_permalink_html( $p, null, 'new_slug-صورة' ); $post = get_post( $p ); $message = 'Scheduled post'; $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found, $message ); + $this->assertContains( '>new_slug-صورة<', $found, $message ); // Draft posts should use preview link - $p = self::factory()->post->create( array( 'post_status' => 'draft', 'post_name' => 'baz' ) ); + $p = self::factory()->post->create( array( 'post_status' => 'draft', 'post_name' => 'baz-صورة' ) ); - $found = get_sample_permalink_html( $p, null, 'new_slug' ); + $found = get_sample_permalink_html( $p, null, 'new_slug-صورة' ); $post = get_post( $p ); $message = 'Draft post'; @@ -336,6 +361,7 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $preview_link = add_query_arg( 'preview', 'true', $preview_link ); $this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message ); + $this->assertContains( '>new_slug-صورة<', $found, $message ); } /**