WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/17/2017 08:14:56 PM (4 years ago)
Author:
westonruter
Message:

Customize: Allow post/page stubs to be edited in WP Admin as "customization drafts" when changeset is saved as draft or scheduled.

  • Update stubs to have draft status when changeset is saved as draft, instead of preventing auto-draft garbage collection by giving them a far-future post_date.
  • Show notice in publish metabox when editing a customization draft indicating that it will be published automatically with its changeset; a link to Customizer is included.
  • Include a new "Customization Draft" display post state in the post list table.
  • Disconnect stubs from their changesets when they are updated with a status other than "Draft".
  • Trash customization drafts when their related changeset is trashed or deleted.
  • Add a _customize_changeset_uuid postmeta to stubs to link them with their associated changeset.
  • Include customize_changeset_uuid as context when requesting to insert a new auto-draft.

Props westonruter, melchoyce.
See #39896, #39752, #34923.
Fixes #42220.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r41204 r41887  
    542542        $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Non-existent', 'post_type' => 'nonexistent' ) );
    543543        $this->assertInstanceOf( 'WP_Post', $r );
     544        $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) );
    544545
    545546        $r = $menus->insert_auto_draft_post( array( 'post_type' => 'post' ) );
     
    556557        $this->assertEquals( '', $r->post_name );
    557558        $this->assertEquals( 'hello-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) );
     559        $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) );
    558560        $this->assertEquals( 'post', $r->post_type );
    559561
     
    564566        $this->assertEquals( '', $r->post_name );
    565567        $this->assertEquals( 'greetings-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) );
     568        $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) );
    566569        $this->assertEquals( 'Hi World', $r->post_content );
    567570    }
     
    717720        ) );
    718721
     722        $draft_post_id = $this->factory()->post->create( array(
     723            'post_status' => 'draft',
     724            'post_title' => 'Draft',
     725            'post_author' => $administrator_user_id,
     726        ) );
     727
     728        $private_post_id = $this->factory()->post->create( array(
     729            'post_status' => 'private',
     730            'post_title' => 'Private',
     731            'post_author' => $administrator_user_id,
     732        ) );
     733
    719734        $value = array(
    720735            'bad',
     
    722737            $author_post_id,
    723738            $administrator_post_id,
     739            $draft_post_id,
     740            $private_post_id,
    724741        );
    725742
     
    734751        wp_set_current_user( $administrator_user_id );
    735752        $sanitized = $menus->sanitize_nav_menus_created_posts( $value );
    736         $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id ), $sanitized );
     753        $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id, $draft_post_id ), $sanitized );
    737754    }
    738755
     
    747764
    748765        $post_ids = array();
    749         for ( $i = 0; $i < 3; $i += 1 ) {
    750             $r = $menus->insert_auto_draft_post( array(
    751                 'post_title' => 'Auto Draft ' . $i,
    752                 'post_type' => 'post',
    753                 'post_name' => 'auto-draft-' . $i,
    754             ) );
    755             $this->assertInstanceOf( 'WP_Post', $r );
    756             $post_ids[] = $r->ID;
    757         }
     766
     767        // Auto-draft.
     768        $r = $menus->insert_auto_draft_post( array(
     769            'post_title' => 'Auto Draft',
     770            'post_type' => 'post',
     771            'post_name' => 'auto-draft-1',
     772        ) );
     773        $this->assertInstanceOf( 'WP_Post', $r );
     774        $post_ids[] = $r->ID;
     775
     776        // Draft.
     777        $r = $menus->insert_auto_draft_post( array(
     778            'post_title' => 'Draft',
     779            'post_type' => 'post',
     780            'post_name' => 'auto-draft-2',
     781        ) );
     782        $this->assertInstanceOf( 'WP_Post', $r );
     783        wp_update_post( array(
     784            'ID' => $r->ID,
     785            'post_status' => 'draft',
     786        ) );
     787        $post_ids[] = $r->ID;
     788
     789        $drafted_post_ids = $post_ids;
     790
     791        // Private (this will exclude it from being considered a stub).
     792        $r = $menus->insert_auto_draft_post( array(
     793            'post_title' => 'Private',
     794            'post_type' => 'post',
     795            'post_name' => 'auto-draft-3',
     796        ) );
     797        $this->assertInstanceOf( 'WP_Post', $r );
     798        wp_update_post( array(
     799            'ID' => $r->ID,
     800            'post_status' => 'private',
     801        ) );
     802        $post_ids[] = $r->ID;
     803        $private_post_id = $r->ID;
     804
     805        // Trashed (this will exclude it from being considered a stub).
     806        $r = $menus->insert_auto_draft_post( array(
     807            'post_title' => 'Trash',
     808            'post_type' => 'post',
     809            'post_name' => 'auto-draft-4',
     810        ) );
     811        $this->assertInstanceOf( 'WP_Post', $r );
     812        wp_trash_post( $r->ID );
     813        $post_ids[] = $r->ID;
     814        $trashed_post_id = $r->ID;
    758815
    759816        $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) );
     
    764821        $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting );
    765822        $this->assertEquals( array( $menus, 'sanitize_nav_menus_created_posts' ), $setting->sanitize_callback );
    766         $this->assertEquals( $post_ids, $setting->post_value() );
    767         foreach ( $post_ids as $post_id ) {
    768             $this->assertEquals( 'auto-draft', get_post_status( $post_id ) );
     823        $this->assertEquals( $drafted_post_ids, $setting->post_value() );
     824        $this->assertArrayNotHasKey( $private_post_id, $post_ids );
     825        $this->assertArrayNotHasKey( $trashed_post_id, $post_ids );
     826
     827        $this->assertEquals( 'auto-draft', get_post_status( $drafted_post_ids[0] ) );
     828        $this->assertEquals( 'draft', get_post_status( $drafted_post_ids[1] ) );
     829        foreach ( $drafted_post_ids as $post_id ) {
    769830            $this->assertEmpty( get_post( $post_id )->post_name );
    770831            $this->assertNotEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
     
    774835        $setting->save();
    775836        $this->assertEquals( $save_action_count + 1, did_action( 'customize_save_nav_menus_created_posts' ) );
    776         foreach ( $post_ids as $post_id ) {
     837        foreach ( $drafted_post_ids as $post_id ) {
    777838            $this->assertEquals( 'publish', get_post_status( $post_id ) );
    778839            $this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name );
     
    780841        }
    781842
     843        $this->assertEquals( 'private', get_post_status( $private_post_id ) );
     844        $this->assertEquals( 'trash', get_post_status( $trashed_post_id ) );
     845
    782846        // Ensure that unique slugs were assigned.
    783         $posts = array_map( 'get_post', $post_ids );
     847        $posts = array_map( 'get_post', $drafted_post_ids );
    784848        $post_names = wp_list_pluck( $posts, 'post_name' );
    785849        $this->assertEqualSets( $post_names, array_unique( $post_names ) );
Note: See TracChangeset for help on using the changeset viewer.