Make WordPress Core


Ignore:
Timestamp:
12/05/2016 07:38:16 PM (7 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/customize/manager.php

    r39435 r39507  
    454454            } else {
    455455                $this->assertEquals( 'auto-draft', $post->post_status );
     456                $this->assertEmpty( $post->post_name );
    456457            }
    457             $posts_by_name[ $post->post_name ] = $post->ID;
     458            $post_name = $post->post_name;
     459            if ( empty( $post_name ) ) {
     460                $post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true );
     461            }
     462            $posts_by_name[ $post_name ] = $post->ID;
    458463        }
    459464        $this->assertEquals( array( 'waffles', 'canola', 'home', 'about', 'blog', 'custom' ), array_keys( $posts_by_name ) );
     
    465470        $attachment_metadata = wp_get_attachment_metadata( $posts_by_name['waffles'] );
    466471        $this->assertEquals( 'Waffles', get_post( $posts_by_name['waffles'] )->post_title );
     472        $this->assertEquals( 'waffles', get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) );
    467473        $this->assertArrayHasKey( 'file', $attachment_metadata );
    468474        $this->assertContains( 'waffles', $attachment_metadata['file'] );
     
    489495        $wp_customize->import_theme_starter_content();
    490496        $changeset_data = $wp_customize->changeset_data();
    491         $this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'], 'Auto-drafts should not get re-created and amended with each import.' );
     497        $this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'] ); // Auto-drafts should not get re-created and amended with each import.
    492498
    493499        // Test that saving non-starter content on top of the changeset clears the starter_content flag.
     
    540546        $this->assertContains( 'waffles', get_header_image() );
    541547        $this->assertContains( 'waffles', get_background_image() );
     548        $this->assertEquals( 'waffles', get_post( $posts_by_name['waffles'] )->post_name );
     549        $this->assertEmpty( get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) );
    542550    }
    543551
Note: See TracChangeset for help on using the changeset viewer.