<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41887] trunk: Customize: Allow post/page stubs to be edited in WP Admin as "customization drafts" when changeset is saved as draft or scheduled.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41887">41887</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41887","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-10-17 20:14:56 +0000 (Tue, 17 Oct 2017)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/39896">#39896</a>, <a href="https://core.trac.wordpress.org/ticket/39752">#39752</a>, <a href="https://core.trac.wordpress.org/ticket/34923">#34923</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/42220">#42220</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincsscommoncss">trunk/src/wp-admin/css/common.css</a></li>
<li><a href="#trunksrcwpadminincludesmetaboxesphp">trunk/src/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunksrcwpadminincludestemplatephp">trunk/src/wp-admin/includes/template.php</a></li>
<li><a href="#trunksrcwpadminjscustomizenavmenusjs">trunk/src/wp-admin/js/customize-nav-menus.js</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizenavmenusphp">trunk/src/wp-includes/class-wp-customize-nav-menus.php</a></li>
<li><a href="#trunksrcwpincludesnavmenuphp">trunk/src/wp-includes/nav-menu.php</a></li>
<li><a href="#trunksrcwpincludesthemephp">trunk/src/wp-includes/theme.php</a></li>
<li><a href="#trunktestsphpunittestsajaxCustomizeMenusphp">trunk/tests/phpunit/tests/ajax/CustomizeMenus.php</a></li>
<li><a href="#trunktestsphpunittestscustomizenavmenusphp">trunk/tests/phpunit/tests/customize/nav-menus.php</a></li>
<li><a href="#trunktestsphpunittestspostnavmenuphp">trunk/tests/phpunit/tests/post/nav-menu.php</a></li>
<li><a href="#trunktestsphpunitteststhemephp">trunk/tests/phpunit/tests/theme.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincsscommoncss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/css/common.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/css/common.css 2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/src/wp-admin/css/common.css   2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -964,6 +964,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">        text-align: right;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+#misc-publishing-actions .notice {
+       margin-left: 10px;
+       margin-right: 10px;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /* Filter bar */
</span><span class="cx" style="display: block; padding: 0 10px"> .wp-filter {
</span><span class="cx" style="display: block; padding: 0 10px">        display: inline-block;
</span></span></pre></div>
<a id="trunksrcwpadminincludesmetaboxesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/meta-boxes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/meta-boxes.php        2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/src/wp-admin/includes/meta-boxes.php  2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -223,6 +223,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </div><?php // /misc-pub-section ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php if ( 'draft' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) : ?>
+       <div class="notice notice-info notice-alt inline">
+               <p>
+                       <?php
+                       echo sprintf(
+                               /* translators: %s is the URL to the Customizer */
+                               __( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there&#8217;s no need to publish now. It will be published automatically with those changes.' ),
+                               esc_url(
+                                       add_query_arg(
+                                               'changeset_uuid',
+                                               rawurlencode( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ),
+                                               admin_url( 'customize.php' )
+                                       )
+                               )
+                       );
+                       ?>
+               </p>
+       </div>
+<?php endif; ?>
+
</ins><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Fires after the post time/date setting in the Publish meta box.
</span></span></pre></div>
<a id="trunksrcwpadminincludestemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/template.php  2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/src/wp-admin/includes/template.php    2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1736,8 +1736,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $post_states['protected'] = __('Password protected');
</span><span class="cx" style="display: block; padding: 0 10px">        if ( 'private' == $post->post_status && 'private' != $post_status )
</span><span class="cx" style="display: block; padding: 0 10px">                $post_states['private'] = __('Private');
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( 'draft' == $post->post_status && 'draft' != $post_status )
-               $post_states['draft'] = __('Draft');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'draft' === $post->post_status ) {
+               if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
+                       $post_states[] = __( 'Customization Draft' );
+               } elseif ( 'draft' !== $post_status ) {
+                       $post_states['draft'] = __( 'Draft' );
+               }
+       } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
+               $post_states[] = __( 'Customization Draft' );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( 'pending' == $post->post_status && 'pending' != $post_status )
</span><span class="cx" style="display: block; padding: 0 10px">                $post_states['pending'] = _x('Pending', 'post status');
</span><span class="cx" style="display: block; padding: 0 10px">        if ( is_sticky($post->ID) )
</span></span></pre></div>
<a id="trunksrcwpadminjscustomizenavmenusjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/customize-nav-menus.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/customize-nav-menus.js      2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/src/wp-admin/js/customize-nav-menus.js        2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -97,6 +97,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                request = wp.ajax.post( 'customize-nav-menus-insert-auto-draft', {
</span><span class="cx" style="display: block; padding: 0 10px">                        'customize-menus-nonce': api.settings.nonce['customize-menus'],
</span><span class="cx" style="display: block; padding: 0 10px">                        'wp_customize': 'on',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'customize_changeset_uuid': api.settings.changeset.uuid,
</ins><span class="cx" style="display: block; padding: 0 10px">                         'params': params
</span><span class="cx" style="display: block; padding: 0 10px">                } );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizenavmenusphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-nav-menus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-nav-menus.php    2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/src/wp-includes/class-wp-customize-nav-menus.php      2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -794,6 +794,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return new WP_Error( 'status_forbidden', __( 'Status is forbidden' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                /*
+                * If the changeset is a draft, this will change to draft the next time the changeset
+                * is updated; otherwise, auto-draft will persist in autosave revisions, until save.
+                */
</ins><span class="cx" style="display: block; padding: 0 10px">                 $postarr['post_status'] = 'auto-draft';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Auto-drafts are allowed to have empty post_names, so it has to be explicitly set.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -804,6 +808,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $postarr['meta_input'] = array();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $postarr['meta_input']['_customize_changeset_uuid'] = $this->manager->changeset_uuid();
</ins><span class="cx" style="display: block; padding: 0 10px">                 unset( $postarr['post_name'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1172,7 +1177,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Sanitize post IDs for auto-draft posts created for nav menu items to be published.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Sanitize post IDs for posts created for nav menu items to be published.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 4.7.0
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1186,7 +1191,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                continue;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                        $post = get_post( $post_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( 'auto-draft' !== $post->post_status ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( 'auto-draft' !== $post->post_status && 'draft' !== $post->post_status ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 continue;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                        $post_type_obj = get_post_type_object( $post->post_type );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1217,6 +1222,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $post_ids = $setting->post_value();
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $post_ids ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( $post_ids as $post_id ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               // Prevent overriding the status that a user may have prematurely updated the post to.
+                               $current_status = get_post_status( $post_id );
+                               if ( 'auto-draft' !== $current_status && 'draft' !== $current_status ) {
+                                       continue;
+                               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish';
</span><span class="cx" style="display: block; padding: 0 10px">                                $args = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'ID' => $post_id,
</span></span></pre></div>
<a id="trunksrcwpincludesnavmenuphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/nav-menu.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/nav-menu.php        2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/src/wp-includes/nav-menu.php  2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1051,10 +1051,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px">        remove_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
-               if ( ! empty( $post_id ) && 'auto-draft' === get_post_status( $post_id ) ) {
-                       wp_delete_post( $post_id, true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $data['nav_menus_created_posts']['value'] as $stub_post_id ) {
+               if ( empty( $stub_post_id ) ) {
+                       continue;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( 'auto-draft' === get_post_status( $stub_post_id ) ) {
+                       wp_delete_post( $stub_post_id, true );
+               } elseif ( 'draft' === get_post_status( $stub_post_id ) ) {
+                       wp_trash_post( $stub_post_id );
+                       delete_post_meta( $stub_post_id, '_customize_changeset_uuid' );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px">        add_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/theme.php   2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/src/wp-includes/theme.php     2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3051,7 +3051,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Make sure that auto-draft posts get their post_date bumped to prevent premature garbage-collection.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Make sure that auto-draft posts get their post_date bumped or status changed to draft to prevent premature garbage-collection.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * When a changeset is updated but remains an auto-draft, ensure the post_date
</span><span class="cx" style="display: block; padding: 0 10px">  * for the auto-draft posts remains the same so that it will be
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3060,6 +3060,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * to have a far-future post_date so that they will never be garbage collected
</span><span class="cx" style="display: block; padding: 0 10px">  * unless the changeset post itself is deleted.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * When a changeset is updated to be a persistent draft or to be scheduled for
+ * publishing, then transition any dependent auto-drafts to a draft status so
+ * that they likewise will not be garbage-collected but also so that they can
+ * be edited in the admin before publishing since there is not yet a post/page
+ * editing flow in the Customizer. See #39752.
+ *
+ * @link https://core.trac.wordpress.org/ticket/39752
+ *
</ins><span class="cx" style="display: block; padding: 0 10px">  * @since 4.8.0
</span><span class="cx" style="display: block; padding: 0 10px">  * @access private
</span><span class="cx" style="display: block; padding: 0 10px">  * @see wp_delete_auto_drafts()
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3078,34 +3086,55 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        $data = json_decode( $post->post_content, true );
+       if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
+               return;
+       }
+
+       /*
+        * Actually, in lieu of keeping alive, trash any customization drafts here if the changeset itself is
+        * getting trashed. This is needed because when a changeset transitions to a draft, then any of the
+        * dependent auto-draft post/page stubs will also get transitioned to customization drafts which
+        * are then visible in the WP Admin. We cannot wait for the deletion of the changeset in which
+        * _wp_delete_customize_changeset_dependent_auto_drafts() will be called, since they need to be
+        * trashed to remove from visibility immediately.
+        */
+       if ( 'trash' === $new_status ) {
+               foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
+                       if ( ! empty( $post_id ) && 'draft' === get_post_status( $post_id ) ) {
+                               wp_trash_post( $post_id );
+                       }
+               }
+               return;
+       }
+
+       $post_args = array();
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( 'auto-draft' === $new_status ) {
</span><span class="cx" style="display: block; padding: 0 10px">                /*
</span><span class="cx" style="display: block; padding: 0 10px">                 * Keep the post date for the post matching the changeset
</span><span class="cx" style="display: block; padding: 0 10px">                 * so that it will not be garbage-collected before the changeset.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $new_post_date = $post->post_date;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $post_args['post_date'] = $post->post_date; // Note wp_delete_auto_drafts() only looks at this date.
</ins><span class="cx" style="display: block; padding: 0 10px">         } else {
</span><span class="cx" style="display: block; padding: 0 10px">                /*
</span><span class="cx" style="display: block; padding: 0 10px">                 * Since the changeset no longer has an auto-draft (and it is not published)
</span><span class="cx" style="display: block; padding: 0 10px">                 * it is now a persistent changeset, a long-lived draft, and so any
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * associated auto-draft posts should have their dates
-                * pushed out very far into the future to prevent them from ever
-                * being garbage-collected.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * associated auto-draft posts should likewise transition into having a draft
+                * status. These drafts will be treated differently than regular drafts in
+                * that they will be tied to the given changeset. The publish metabox is
+                * replaced with a notice about how the post is part of a set of customized changes
+                * which will be published when the changeset is published.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $new_post_date = gmdate( 'Y-m-d H:i:d', strtotime( '+100 years' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $post_args['post_status'] = 'draft';
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $data = json_decode( $post->post_content, true );
-       if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
-               return;
-       }
</del><span class="cx" style="display: block; padding: 0 10px">         foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        continue;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                $wpdb->update(
</span><span class="cx" style="display: block; padding: 0 10px">                        $wpdb->posts,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        array( 'post_date' => $new_post_date ), // Note wp_delete_auto_drafts() only looks at this date.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $post_args,
</ins><span class="cx" style="display: block; padding: 0 10px">                         array( 'ID' => $post_id )
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                clean_post_cache( $post_id );
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxCustomizeMenusphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/ajax/CustomizeMenus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/CustomizeMenus.php 2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/tests/phpunit/tests/ajax/CustomizeMenus.php   2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -603,6 +603,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'post', $post->post_type );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( '', $post->post_name );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'hello-world', get_post_meta( $post->ID, '_customize_draft_post_name', true ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $post->ID, '_customize_changeset_uuid', true ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="trunktestsphpunittestscustomizenavmenusphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/customize/nav-menus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/customize/nav-menus.php 2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/tests/phpunit/tests/customize/nav-menus.php   2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -541,6 +541,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Non-existent post types allowed as of #39610.
</span><span class="cx" style="display: block; padding: 0 10px">                $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Non-existent', 'post_type' => 'nonexistent' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertInstanceOf( 'WP_Post', $r );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $r = $menus->insert_auto_draft_post( array( 'post_type' => 'post' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertInstanceOf( 'WP_Error', $r );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -555,6 +556,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'Hello World', $r->post_title );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( '', $r->post_name );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'hello-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( 'post', $r->post_type );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Hello World', 'post_type' => 'post', 'post_name' => 'greetings-world', 'post_content' => 'Hi World' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -563,6 +565,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'post', $r->post_type );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( '', $r->post_name );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'greetings-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( 'Hi World', $r->post_content );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -716,11 +719,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_author' => $administrator_user_id,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $draft_post_id = $this->factory()->post->create( array(
+                       'post_status' => 'draft',
+                       'post_title' => 'Draft',
+                       'post_author' => $administrator_user_id,
+               ) );
+
+               $private_post_id = $this->factory()->post->create( array(
+                       'post_status' => 'private',
+                       'post_title' => 'Private',
+                       'post_author' => $administrator_user_id,
+               ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $value = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'bad',
</span><span class="cx" style="display: block; padding: 0 10px">                        $contributor_post_id,
</span><span class="cx" style="display: block; padding: 0 10px">                        $author_post_id,
</span><span class="cx" style="display: block; padding: 0 10px">                        $administrator_post_id,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $draft_post_id,
+                       $private_post_id,
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( $contributor_user_id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -733,7 +750,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( $administrator_user_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $sanitized = $menus->sanitize_nav_menus_created_posts( $value );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id ), $sanitized );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id, $draft_post_id ), $sanitized );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -746,16 +763,56 @@
</span><span class="cx" style="display: block; padding: 0 10px">                do_action( 'customize_register', $this->wp_customize );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $post_ids = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                for ( $i = 0; $i < 3; $i += 1 ) {
-                       $r = $menus->insert_auto_draft_post( array(
-                               'post_title' => 'Auto Draft ' . $i,
-                               'post_type' => 'post',
-                               'post_name' => 'auto-draft-' . $i,
-                       ) );
-                       $this->assertInstanceOf( 'WP_Post', $r );
-                       $post_ids[] = $r->ID;
-               }
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Auto-draft.
+               $r = $menus->insert_auto_draft_post( array(
+                       'post_title' => 'Auto Draft',
+                       'post_type' => 'post',
+                       'post_name' => 'auto-draft-1',
+               ) );
+               $this->assertInstanceOf( 'WP_Post', $r );
+               $post_ids[] = $r->ID;
+
+               // Draft.
+               $r = $menus->insert_auto_draft_post( array(
+                       'post_title' => 'Draft',
+                       'post_type' => 'post',
+                       'post_name' => 'auto-draft-2',
+               ) );
+               $this->assertInstanceOf( 'WP_Post', $r );
+               wp_update_post( array(
+                       'ID' => $r->ID,
+                       'post_status' => 'draft',
+               ) );
+               $post_ids[] = $r->ID;
+
+               $drafted_post_ids = $post_ids;
+
+               // Private (this will exclude it from being considered a stub).
+               $r = $menus->insert_auto_draft_post( array(
+                       'post_title' => 'Private',
+                       'post_type' => 'post',
+                       'post_name' => 'auto-draft-3',
+               ) );
+               $this->assertInstanceOf( 'WP_Post', $r );
+               wp_update_post( array(
+                       'ID' => $r->ID,
+                       'post_status' => 'private',
+               ) );
+               $post_ids[] = $r->ID;
+               $private_post_id = $r->ID;
+
+               // Trashed (this will exclude it from being considered a stub).
+               $r = $menus->insert_auto_draft_post( array(
+                       'post_title' => 'Trash',
+                       'post_type' => 'post',
+                       'post_name' => 'auto-draft-4',
+               ) );
+               $this->assertInstanceOf( 'WP_Post', $r );
+               wp_trash_post( $r->ID );
+               $post_ids[] = $r->ID;
+               $trashed_post_id = $r->ID;
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $setting_id = 'nav_menus_created_posts';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -763,9 +820,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $setting = $this->wp_customize->get_setting( $setting_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( array( $menus, 'sanitize_nav_menus_created_posts' ), $setting->sanitize_callback );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $post_ids, $setting->post_value() );
-               foreach ( $post_ids as $post_id ) {
-                       $this->assertEquals( 'auto-draft', get_post_status( $post_id ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $drafted_post_ids, $setting->post_value() );
+               $this->assertArrayNotHasKey( $private_post_id, $post_ids );
+               $this->assertArrayNotHasKey( $trashed_post_id, $post_ids );
+
+               $this->assertEquals( 'auto-draft', get_post_status( $drafted_post_ids[0] ) );
+               $this->assertEquals( 'draft', get_post_status( $drafted_post_ids[1] ) );
+               foreach ( $drafted_post_ids as $post_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $this->assertEmpty( get_post( $post_id )->post_name );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertNotEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -773,14 +834,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $save_action_count = did_action( 'customize_save_nav_menus_created_posts' );
</span><span class="cx" style="display: block; padding: 0 10px">                $setting->save();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $save_action_count + 1, did_action( 'customize_save_nav_menus_created_posts' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                foreach ( $post_ids as $post_id ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         foreach ( $drafted_post_ids as $post_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $this->assertEquals( 'publish', get_post_status( $post_id ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( 'private', get_post_status( $private_post_id ) );
+               $this->assertEquals( 'trash', get_post_status( $trashed_post_id ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Ensure that unique slugs were assigned.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $posts = array_map( 'get_post', $post_ids );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $posts = array_map( 'get_post', $drafted_post_ids );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $post_names = wp_list_pluck( $posts, 'post_name' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEqualSets( $post_names, array_unique( $post_names ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span></span></pre></div>
<a id="trunktestsphpunittestspostnavmenuphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/nav-menu.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/nav-menu.php       2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/tests/phpunit/tests/post/nav-menu.php 2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -549,9 +549,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @covers _wp_delete_customize_changeset_dependent_auto_drafts()
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        function test_wp_delete_customize_changeset_dependent_auto_drafts() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $nav_created_post_ids = $this->factory()->post->create_many(2, array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $auto_draft_post_id = $this->factory()->post->create( array(
</ins><span class="cx" style="display: block; padding: 0 10px">                         'post_status' => 'auto-draft',
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $draft_post_id = $this->factory()->post->create( array(
+                       'post_status' => 'draft',
+               ) );
+               $private_post_id = $this->factory()->post->create( array(
+                       'post_status' => 'private',
+               ) );
+
+               $nav_created_post_ids = array(
+                       $auto_draft_post_id,
+                       $draft_post_id,
+                       $private_post_id,
+               );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $data = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'nav_menus_created_posts' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'value' => $nav_created_post_ids,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -566,11 +578,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $wp_customize->save_changeset_post( array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'data' => $data,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[0] ) );
-               $this->assertInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[1] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( 'auto-draft', get_post_status( $auto_draft_post_id ) );
+               $this->assertEquals( 'draft', get_post_status( $draft_post_id ) );
+               $this->assertEquals( 'private', get_post_status( $private_post_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 wp_delete_post( $wp_customize->changeset_post_id(), true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[0] ) );
-               $this->assertNotInstanceOf( 'WP_Post', get_post( $nav_created_post_ids[1] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertFalse( get_post_status( $auto_draft_post_id ) );
+               $this->assertEquals( 'trash', get_post_status( $draft_post_id ) );
+               $this->assertEquals( 'private', get_post_status( $private_post_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="trunktestsphpunitteststhemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme.php       2017-10-16 23:01:55 UTC (rev 41886)
+++ trunk/tests/phpunit/tests/theme.php 2017-10-17 20:14:56 UTC (rev 41887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -318,6 +318,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function test_wp_keep_alive_customize_changeset_dependent_auto_drafts() {
</span><span class="cx" style="display: block; padding: 0 10px">                $nav_created_post_ids = $this->factory()->post->create_many(2, array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_status' => 'auto-draft',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-2 days' ) ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'nav_menus_created_posts' => array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -328,17 +329,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">                require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
</span><span class="cx" style="display: block; padding: 0 10px">                $wp_customize = new WP_Customize_Manager();
</span><span class="cx" style="display: block; padding: 0 10px">                do_action( 'customize_register', $wp_customize );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               // 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().
</ins><span class="cx" style="display: block; padding: 0 10px">                 $wp_customize->save_changeset_post( array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'data' => $data,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( get_post( $nav_created_post_ids[0] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( get_post( $nav_created_post_ids[1] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertEquals( 'auto-draft', get_post_status( $nav_created_post_ids[0] ) );
+               $this->assertEquals( 'auto-draft', get_post_status( $nav_created_post_ids[1] ) );
+
+               // Stubs transition to drafts when changeset is saved as a draft.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $wp_customize->save_changeset_post( array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'status' => 'draft',
</span><span class="cx" style="display: block; padding: 0 10px">                        'data' => $data,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $expected_year = date( 'Y' ) + 100;
-               $this->assertEquals( $expected_year, date( 'Y', strtotime( get_post( $nav_created_post_ids[0] )->post_date ) ) );
-               $this->assertEquals( $expected_year, date( 'Y', strtotime( get_post( $nav_created_post_ids[1] )->post_date ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( get_post( $nav_created_post_ids[0] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date );
+               $this->assertEquals( get_post( $nav_created_post_ids[1] )->post_date, get_post( $wp_customize->changeset_post_id() )->post_date );
+               $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[0] ) );
+               $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[1] ) );
+
+               // Status remains unchanged for stub that the user broke out of the changeset.
+               wp_update_post( array(
+                       'ID' => $nav_created_post_ids[1],
+                       'post_status' => 'private',
+               ) );
+               $wp_customize->save_changeset_post( array(
+                       'status' => 'draft',
+                       'data' => $data,
+               ) );
+               $this->assertEquals( 'draft', get_post_status( $nav_created_post_ids[0] ) );
+               $this->assertEquals( 'private', get_post_status( $nav_created_post_ids[1] ) );
+
+               // Draft stub is trashed when the changeset is trashed.
+               $wp_customize->trash_changeset_post( $wp_customize->changeset_post_id() );
+               $this->assertEquals( 'trash', get_post_status( $nav_created_post_ids[0] ) );
+               $this->assertEquals( 'private', get_post_status( $nav_created_post_ids[1] ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>