Ticket #18962: 18962.patch
File 18962.patch, 3.4 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 3b3d55f..771c95e 100644
function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 3703 3703 * Page slugs must be unique within their own trees. Pages are in a separate 3704 3704 * namespace than posts so page slugs are allowed to overlap post slugs. 3705 3705 */ 3706 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %sAND ID != %d AND post_parent = %d LIMIT 1";3706 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1"; 3707 3707 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) ); 3708 3708 3709 3709 /** … … function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 3720 3720 $suffix = 2; 3721 3721 do { 3722 3722 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3723 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) ); 3723 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) ); 3724 3724 $suffix++; 3725 3725 } while ( $post_name_check ); 3726 3726 $slug = $alt_post_name; -
tests/phpunit/tests/post.php
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php index 2375458..1200b98 100644
class Tests_Post extends WP_UnitTestCase { 508 508 $page = $this->factory->post->create_and_get( array( 'post_title' => 'some-page', 'post_type' => 'page' ) ); 509 509 $other_att = $this->factory->post->create_and_get( array( 'post_title' => 'some-other-page', 'post_type' => 'attachment' ) ); 510 510 511 global $wpdb; 512 $wpdb->update( $wpdb->posts, array( 'post_name' => 'some-page' ), array( 'ID' => $page->ID ) ); 513 clean_post_cache( $page->ID ); 514 515 $page = get_post( $page->ID ); 516 511 517 $this->assertEquals( 'some-page', $attachment->post_name ); 512 518 $this->assertEquals( 'some-page', $page->post_name ); 513 519 … … class Tests_Post extends WP_UnitTestCase { 988 994 } 989 995 990 996 /** 997 * @ticket 18962 998 */ 999 function test_wp_unique_post_slug_with_hierarchy_and_attachments() { 1000 register_post_type( 'post-type-1', array( 'hierarchical' => true ) ); 1001 1002 $args = array( 1003 'post_type' => 'post-type-1', 1004 'post_name' => 'some-slug', 1005 'post_status' => 'publish', 1006 ); 1007 $one = $this->factory->post->create( $args ); 1008 1009 $args = array( 1010 'post_mime_type' => 'image/jpeg', 1011 'post_type' => 'attachment', 1012 'post_name' => 'image' 1013 ); 1014 $attachment = $this->factory->attachment->create_object( 'image.jpg', $one, $args ); 1015 1016 $args = array( 1017 'post_type' => 'post-type-1', 1018 'post_name' => 'image', 1019 'post_status' => 'publish', 1020 'post_parent' => $one 1021 ); 1022 $two = $this->factory->post->create( $args ); 1023 1024 $this->assertEquals( 'some-slug', get_post( $one )->post_name ); 1025 $this->assertEquals( 'image', get_post( $attachment )->post_name ); 1026 $this->assertEquals( 'image-2', get_post( $two )->post_name ); 1027 1028 // 'image' can be a child of image-2 1029 $this->assertEquals( 'image', wp_unique_post_slug( 'image', 0, 'publish', 'post-type-1', $two ) ); 1030 1031 _unregister_post_type( 'post-type-1' ); 1032 } 1033 1034 /** 991 1035 * @ticket 21212 992 1036 */ 993 1037 function test_utf8mb3_post_saves_with_emoji() {