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/theme.php

    r40676 r41887  
    319319        $nav_created_post_ids = $this->factory()->post->create_many(2, array(
    320320            'post_status' => 'auto-draft',
     321            'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 days' ) ),
    321322        ) );
    322323        $data = array(
     
    329330        $wp_customize = new WP_Customize_Manager();
    330331        do_action( 'customize_register', $wp_customize );
     332
     333        // The post_date for auto-drafts is bumped to match the changeset post_date whenever it is modified to keep them from from being garbage collected by wp_delete_auto_drafts().
    331334        $wp_customize->save_changeset_post( array(
    332335            'data' => $data,
     
    334337        $this->assertEquals( get_post( $nav_created_post_ids[0] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date );
    335338        $this->assertEquals( get_post( $nav_created_post_ids[1] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date );
     339        $this->assertEquals( 'auto-draft', get_post_status( $nav_created_post_ids[0] ) );
     340        $this->assertEquals( 'auto-draft', get_post_status( $nav_created_post_ids[1] ) );
     341
     342        // Stubs transition to drafts when changeset is saved as a draft.
    336343        $wp_customize->save_changeset_post( array(
    337344            'status' => 'draft',
    338345            'data' => $data,
    339346        ) );
    340         $expected_year = date( 'Y' ) + 100;
    341         $this->assertEquals( $expected_year, date( 'Y', strtotime( get_post( $nav_created_post_ids[0] )->post_date ) ) );
    342         $this->assertEquals( $expected_year, date( 'Y', strtotime( get_post( $nav_created_post_ids[1] )->post_date ) ) );
     347        $this->assertEquals( get_post( $nav_created_post_ids[0] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date );
     348        $this->assertEquals( get_post( $nav_created_post_ids[1] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date );
     349        $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[0] ) );
     350        $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[1] ) );
     351
     352        // Status remains unchanged for stub that the user broke out of the changeset.
     353        wp_update_post( array(
     354            'ID' => $nav_created_post_ids[1],
     355            'post_status' => 'private',
     356        ) );
     357        $wp_customize->save_changeset_post( array(
     358            'status' => 'draft',
     359            'data' => $data,
     360        ) );
     361        $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[0] ) );
     362        $this->assertEquals( 'private', get_post_status( $nav_created_post_ids[1] ) );
     363
     364        // Draft stub is trashed when the changeset is trashed.
     365        $wp_customize->trash_changeset_post( $wp_customize->changeset_post_id() );
     366        $this->assertEquals( 'trash', get_post_status( $nav_created_post_ids[0] ) );
     367        $this->assertEquals( 'private', get_post_status( $nav_created_post_ids[1] ) );
    343368    }
    344369}
Note: See TracChangeset for help on using the changeset viewer.