Make WordPress Core

Ticket #18962: 18962.patch

File 18962.patch, 3.4 KB (added by boonebgorges, 9 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 
    37033703                 * Page slugs must be unique within their own trees. Pages are in a separate
    37043704                 * namespace than posts so page slugs are allowed to overlap post slugs.
    37053705                 */
    3706                 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND 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";
    37073707                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
    37083708
    37093709                /**
    function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p 
    37203720                        $suffix = 2;
    37213721                        do {
    37223722                                $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 ) );
    37243724                                $suffix++;
    37253725                        } while ( $post_name_check );
    37263726                        $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 { 
    508508                $page       = $this->factory->post->create_and_get( array( 'post_title' => 'some-page', 'post_type' => 'page' ) );
    509509                $other_att  = $this->factory->post->create_and_get( array( 'post_title' => 'some-other-page', 'post_type' => 'attachment' ) );
    510510
     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
    511517                $this->assertEquals( 'some-page', $attachment->post_name );
    512518                $this->assertEquals( 'some-page', $page->post_name );
    513519
    class Tests_Post extends WP_UnitTestCase { 
    988994        }
    989995
    990996        /**
     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        /**
    9911035         * @ticket 21212
    9921036         */
    9931037        function test_utf8mb3_post_saves_with_emoji() {