Make WordPress Core


Ignore:
Timestamp:
12/02/2016 12:24:19 AM (10 years ago)
Author:
westonruter
Message:

Customize: Reuse existing non-auto-draft posts and existing auto-draft posts in the customized state with matching slugs when applying starter content.

  • Updates wp_unique_post_slug() to ignore auto-draft posts. Prevents publishing multiple posts that have the same slugs from starter content.
  • Fixes fatal error when attempting to save an header_image setting from a non-admin context.
  • Fixes substituting attachment symbols in options and theme mods.
  • Fixes applying starter content for header images and background images.

See #38114.
Fixes #38928.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/wpUniquePostSlug.php

    r38938 r39411  
    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        }
    350392}
Note: See TracChangeset for help on using the changeset viewer.