WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/05/2016 07:38:16 PM (4 years ago)
Author:
westonruter
Message:

Customize: Defer populating post_name for auto-draft posts in customized state until posts are published.

The ultimate post_name is stored in postmeta until the post is published. The get_page_by_path() function does not exclude auto-draft posts. Revert changes to wp_unique_post_slug() from [39411] which excluded auto-draft posts.

Props westonruter, dlh for testing, helen for testing.
Merges [39506] onto 4.7 branch.
Fixes #39078 for 4.7.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/tests/phpunit/tests/post/wpUniquePostSlug.php

    r39412 r39507  
    348348        $this->assertSame( 'embed-2', $found );
    349349    }
    350 
    351     /**
    352      * @ticket 38928
    353      */
    354     public function test_non_unique_slugs_for_existing_auto_draft_posts() {
    355         $auto_draft_post_id = self::factory()->post->create( array(
    356             'post_type' => 'post',
    357             'post_name' => 'existing-post',
    358             'post_status' => 'auto-draft',
    359         ) );
    360         $auto_draft_page_id = self::factory()->post->create( array(
    361             'post_type' => 'page',
    362             'post_name' => 'existing-page',
    363             'post_status' => 'auto-draft',
    364         ) );
    365         $auto_draft_attachment_id = self::factory()->attachment->create_object( 'image.jpg', $auto_draft_page_id, array(
    366             'post_mime_type' => 'image/jpeg',
    367             'post_type' => 'attachment',
    368             'post_name' => 'existing-attachment',
    369             'post_status' => 'auto-draft',
    370         ) );
    371 
    372         $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );
    373         $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
    374         $attachment_id = self::factory()->attachment->create_object( 'image2.jpg', $page_id, array(
    375             'post_mime_type' => 'image/jpeg',
    376             'post_type' => 'attachment',
    377             'post_name' => 'existing-image',
    378         ) );
    379 
    380         $this->assertEquals( 'existing-post', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) );
    381         wp_publish_post( $auto_draft_post_id );
    382         $this->assertEquals( 'existing-post-2', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) );
    383 
    384         $this->assertEquals( 'existing-page', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) );
    385         wp_publish_post( $auto_draft_page_id );
    386         $this->assertEquals( 'existing-page-2', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) );
    387 
    388         $this->assertEquals( 'existing-attachment', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) );
    389         wp_publish_post( $auto_draft_attachment_id );
    390         $this->assertEquals( 'existing-attachment-2', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) );
    391     }
    392350}
Note: See TracChangeset for help on using the changeset viewer.