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.


git-svn-id: https://develop.svn.wordpress.org/trunk@39411 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2016-12-02 00:24:19 +00:00
parent 3e9a2d5a5a
commit bdd33e9dff
5 changed files with 269 additions and 60 deletions
@@ -347,4 +347,46 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
$found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 );
$this->assertSame( 'embed-2', $found );
}
/**
* @ticket 38928
*/
public function test_non_unique_slugs_for_existing_auto_draft_posts() {
$auto_draft_post_id = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'existing-post',
'post_status' => 'auto-draft',
) );
$auto_draft_page_id = self::factory()->post->create( array(
'post_type' => 'page',
'post_name' => 'existing-page',
'post_status' => 'auto-draft',
) );
$auto_draft_attachment_id = self::factory()->attachment->create_object( 'image.jpg', $auto_draft_page_id, array(
'post_mime_type' => 'image/jpeg',
'post_type' => 'attachment',
'post_name' => 'existing-attachment',
'post_status' => 'auto-draft',
) );
$post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );
$page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
$attachment_id = self::factory()->attachment->create_object( 'image2.jpg', $page_id, array(
'post_mime_type' => 'image/jpeg',
'post_type' => 'attachment',
'post_name' => 'existing-image',
) );
$this->assertEquals( 'existing-post', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) );
wp_publish_post( $auto_draft_post_id );
$this->assertEquals( 'existing-post-2', wp_unique_post_slug( 'existing-post', $post_id, 'publish', get_post_type( $post_id ), 0 ) );
$this->assertEquals( 'existing-page', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) );
wp_publish_post( $auto_draft_page_id );
$this->assertEquals( 'existing-page-2', wp_unique_post_slug( 'existing-page', $page_id, 'publish', get_post_type( $page_id ), 0 ) );
$this->assertEquals( 'existing-attachment', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) );
wp_publish_post( $auto_draft_attachment_id );
$this->assertEquals( 'existing-attachment-2', wp_unique_post_slug( 'existing-attachment', $attachment_id, 'publish', get_post_type( $attachment_id ), 0 ) );
}
}