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/customize/nav-menus.php

    r39038 r39507  
    550550        $this->assertInstanceOf( 'WP_Post', $r );
    551551        $this->assertEquals( 'Hello World', $r->post_title );
    552         $this->assertEquals( 'hello-world', $r->post_name );
     552        $this->assertEquals( '', $r->post_name );
     553        $this->assertEquals( 'hello-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) );
    553554        $this->assertEquals( 'post', $r->post_type );
    554555
     
    557558        $this->assertEquals( 'Hello World', $r->post_title );
    558559        $this->assertEquals( 'post', $r->post_type );
    559         $this->assertEquals( 'greetings-world', $r->post_name );
     560        $this->assertEquals( '', $r->post_name );
     561        $this->assertEquals( 'greetings-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) );
    560562        $this->assertEquals( 'Hi World', $r->post_content );
    561563    }
     
    740742        do_action( 'customize_register', $this->wp_customize );
    741743
    742         $post_ids = $this->factory()->post->create_many( 3, array(
    743             'post_status' => 'auto-draft',
    744             'post_type' => 'post',
    745             'post_name' => 'auto-draft',
    746         ) );
     744        $post_ids = array();
     745        for ( $i = 0; $i < 3; $i += 1 ) {
     746            $r = $menus->insert_auto_draft_post( array(
     747                'post_title' => 'Auto Draft ' . $i,
     748                'post_type' => 'post',
     749                'post_name' => 'auto-draft-' . $i,
     750            ) );
     751            $this->assertInstanceOf( 'WP_Post', $r );
     752            $post_ids[] = $r->ID;
     753        }
     754
    747755        $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) );
    748756
     
    755763        foreach ( $post_ids as $post_id ) {
    756764            $this->assertEquals( 'auto-draft', get_post_status( $post_id ) );
     765            $this->assertEmpty( get_post( $post_id )->post_name );
     766            $this->assertNotEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
    757767        }
    758768
     
    762772        foreach ( $post_ids as $post_id ) {
    763773            $this->assertEquals( 'publish', get_post_status( $post_id ) );
     774            $this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name );
     775            $this->assertEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
    764776        }
    765777
Note: See TracChangeset for help on using the changeset viewer.