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.


git-svn-id: https://develop.svn.wordpress.org/trunk@41887 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2017-10-17 20:14:56 +00:00
parent ee678ee1f5
commit ce7a93c235
11 changed files with 225 additions and 41 deletions
@@ -794,6 +794,10 @@ final class WP_Customize_Nav_Menus {
return new WP_Error( 'status_forbidden', __( 'Status is forbidden' ) );
}
/*
* 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.
*/
$postarr['post_status'] = 'auto-draft';
// Auto-drafts are allowed to have empty post_names, so it has to be explicitly set.
@@ -804,6 +808,7 @@ final class WP_Customize_Nav_Menus {
$postarr['meta_input'] = array();
}
$postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name'];
$postarr['meta_input']['_customize_changeset_uuid'] = $this->manager->changeset_uuid();
unset( $postarr['post_name'] );
add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 );
@@ -1172,7 +1177,7 @@ final class WP_Customize_Nav_Menus {
}
/**
* Sanitize post IDs for auto-draft posts created for nav menu items to be published.
* Sanitize post IDs for posts created for nav menu items to be published.
*
* @since 4.7.0
*
@@ -1186,7 +1191,7 @@ final class WP_Customize_Nav_Menus {
continue;
}
$post = get_post( $post_id );
if ( 'auto-draft' !== $post->post_status ) {
if ( 'auto-draft' !== $post->post_status && 'draft' !== $post->post_status ) {
continue;
}
$post_type_obj = get_post_type_object( $post->post_type );
@@ -1217,6 +1222,13 @@ final class WP_Customize_Nav_Menus {
$post_ids = $setting->post_value();
if ( ! empty( $post_ids ) ) {
foreach ( $post_ids as $post_id ) {
// 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;
}
$target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish';
$args = array(
'ID' => $post_id,