diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 98aeef597f..ccb11de728 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -6126,11 +6126,11 @@ function wp_add_trashed_suffix_to_post_name_for_post( $post ) { $post = get_post( $post ); - if ( strpos( $post->post_name, '-%trashed%' ) ) { + if ( '__trashed' === substr( $post->post_name, -9 ) ) { return $post->post_name; } add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name ); - $post_name = _truncate_post_slug( $post->post_name, 190 ) . '-%trashed%'; + $post_name = _truncate_post_slug( $post->post_name, 191 ) . '__trashed'; $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); clean_post_cache( $post->ID ); return $post_name; diff --git a/tests/phpunit/tests/post/wpInsertPost.php b/tests/phpunit/tests/post/wpInsertPost.php index deb95701cc..f0e150a8c8 100644 --- a/tests/phpunit/tests/post/wpInsertPost.php +++ b/tests/phpunit/tests/post/wpInsertPost.php @@ -15,7 +15,21 @@ class Tests_WPInsertPost extends WP_UnitTestCase { 'post_status' => 'publish' ) ); wp_trash_post( $trashed_about_page_id ); - $this->assertEquals( 'about-%trashed%', get_post( $trashed_about_page_id )->post_name ); + $this->assertEquals( 'about__trashed', get_post( $trashed_about_page_id )->post_name ); + } + + /** + * @ticket 11863 + */ + public function test_trashed_suffix_should_be_added_to_post_with__trashed_in_slug() { + $trashed_about_page_id = self::factory()->post->create( array( + 'post_type' => 'page', + 'post_title' => 'About', + 'post_status' => 'publish', + 'post_name' => 'foo__trashed__foo', + ) ); + wp_trash_post( $trashed_about_page_id ); + $this->assertEquals( 'foo__trashed__foo__trashed', get_post( $trashed_about_page_id )->post_name ); } /** @@ -49,7 +63,7 @@ class Tests_WPInsertPost extends WP_UnitTestCase { 'post_status' => 'publish' ) ); - $this->assertEquals( 'about-%trashed%', get_post( $trashed_about_page_id )->post_name ); + $this->assertEquals( 'about__trashed', get_post( $trashed_about_page_id )->post_name ); $this->assertEquals( 'about', get_post( $about_page_id )->post_name ); }