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. Built from https://develop.svn.wordpress.org/trunk@41887 git-svn-id: http://core.svn.wordpress.org/trunk@41721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
955d5b0ab1
commit
bd9d1d9178
|
@ -964,6 +964,11 @@ th.action-links {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#misc-publishing-actions .notice {
|
||||||
|
margin-right: 10px;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Filter bar */
|
/* Filter bar */
|
||||||
.wp-filter {
|
.wp-filter {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -964,6 +964,11 @@ th.action-links {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#misc-publishing-actions .notice {
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Filter bar */
|
/* Filter bar */
|
||||||
.wp-filter {
|
.wp-filter {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -223,6 +223,26 @@ if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
|
||||||
</div><?php // /misc-pub-section ?>
|
</div><?php // /misc-pub-section ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?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’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; ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Fires after the post time/date setting in the Publish meta box.
|
* Fires after the post time/date setting in the Publish meta box.
|
||||||
|
|
|
@ -1736,8 +1736,15 @@ function _post_states($post) {
|
||||||
$post_states['protected'] = __('Password protected');
|
$post_states['protected'] = __('Password protected');
|
||||||
if ( 'private' == $post->post_status && 'private' != $post_status )
|
if ( 'private' == $post->post_status && 'private' != $post_status )
|
||||||
$post_states['private'] = __('Private');
|
$post_states['private'] = __('Private');
|
||||||
if ( 'draft' == $post->post_status && 'draft' != $post_status )
|
if ( 'draft' === $post->post_status ) {
|
||||||
$post_states['draft'] = __('Draft');
|
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' );
|
||||||
|
}
|
||||||
if ( 'pending' == $post->post_status && 'pending' != $post_status )
|
if ( 'pending' == $post->post_status && 'pending' != $post_status )
|
||||||
$post_states['pending'] = _x('Pending', 'post status');
|
$post_states['pending'] = _x('Pending', 'post status');
|
||||||
if ( is_sticky($post->ID) )
|
if ( is_sticky($post->ID) )
|
||||||
|
|
|
@ -97,6 +97,7 @@
|
||||||
request = wp.ajax.post( 'customize-nav-menus-insert-auto-draft', {
|
request = wp.ajax.post( 'customize-nav-menus-insert-auto-draft', {
|
||||||
'customize-menus-nonce': api.settings.nonce['customize-menus'],
|
'customize-menus-nonce': api.settings.nonce['customize-menus'],
|
||||||
'wp_customize': 'on',
|
'wp_customize': 'on',
|
||||||
|
'customize_changeset_uuid': api.settings.changeset.uuid,
|
||||||
'params': params
|
'params': params
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -794,6 +794,10 @@ final class WP_Customize_Nav_Menus {
|
||||||
return new WP_Error( 'status_forbidden', __( 'Status is forbidden' ) );
|
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';
|
$postarr['post_status'] = 'auto-draft';
|
||||||
|
|
||||||
// Auto-drafts are allowed to have empty post_names, so it has to be explicitly set.
|
// 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'] = array();
|
||||||
}
|
}
|
||||||
$postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name'];
|
$postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name'];
|
||||||
|
$postarr['meta_input']['_customize_changeset_uuid'] = $this->manager->changeset_uuid();
|
||||||
unset( $postarr['post_name'] );
|
unset( $postarr['post_name'] );
|
||||||
|
|
||||||
add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 );
|
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
|
* @since 4.7.0
|
||||||
*
|
*
|
||||||
|
@ -1186,7 +1191,7 @@ final class WP_Customize_Nav_Menus {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$post = get_post( $post_id );
|
$post = get_post( $post_id );
|
||||||
if ( 'auto-draft' !== $post->post_status ) {
|
if ( 'auto-draft' !== $post->post_status && 'draft' !== $post->post_status ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$post_type_obj = get_post_type_object( $post->post_type );
|
$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();
|
$post_ids = $setting->post_value();
|
||||||
if ( ! empty( $post_ids ) ) {
|
if ( ! empty( $post_ids ) ) {
|
||||||
foreach ( $post_ids as $post_id ) {
|
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';
|
$target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish';
|
||||||
$args = array(
|
$args = array(
|
||||||
'ID' => $post_id,
|
'ID' => $post_id,
|
||||||
|
|
|
@ -1051,9 +1051,15 @@ function _wp_delete_customize_changeset_dependent_auto_drafts( $post_id ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
remove_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
|
remove_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
|
||||||
foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
|
foreach ( $data['nav_menus_created_posts']['value'] as $stub_post_id ) {
|
||||||
if ( ! empty( $post_id ) && 'auto-draft' === get_post_status( $post_id ) ) {
|
if ( empty( $stub_post_id ) ) {
|
||||||
wp_delete_post( $post_id, true );
|
continue;
|
||||||
|
}
|
||||||
|
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' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
|
add_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
|
||||||
|
|
|
@ -3051,7 +3051,7 @@ function is_customize_preview() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure that auto-draft posts get their post_date bumped to prevent premature garbage-collection.
|
* Make sure that auto-draft posts get their post_date bumped or status changed to draft to prevent premature garbage-collection.
|
||||||
*
|
*
|
||||||
* When a changeset is updated but remains an auto-draft, ensure the post_date
|
* When a changeset is updated but remains an auto-draft, ensure the post_date
|
||||||
* for the auto-draft posts remains the same so that it will be
|
* for the auto-draft posts remains the same so that it will be
|
||||||
|
@ -3060,6 +3060,14 @@ function is_customize_preview() {
|
||||||
* to have a far-future post_date so that they will never be garbage collected
|
* to have a far-future post_date so that they will never be garbage collected
|
||||||
* unless the changeset post itself is deleted.
|
* unless the changeset post itself is deleted.
|
||||||
*
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
* @since 4.8.0
|
* @since 4.8.0
|
||||||
* @access private
|
* @access private
|
||||||
* @see wp_delete_auto_drafts()
|
* @see wp_delete_auto_drafts()
|
||||||
|
@ -3078,34 +3086,55 @@ function _wp_keep_alive_customize_changeset_dependent_auto_drafts( $new_status,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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();
|
||||||
if ( 'auto-draft' === $new_status ) {
|
if ( 'auto-draft' === $new_status ) {
|
||||||
/*
|
/*
|
||||||
* Keep the post date for the post matching the changeset
|
* Keep the post date for the post matching the changeset
|
||||||
* so that it will not be garbage-collected before the changeset.
|
* so that it will not be garbage-collected before the changeset.
|
||||||
*/
|
*/
|
||||||
$new_post_date = $post->post_date;
|
$post_args['post_date'] = $post->post_date; // Note wp_delete_auto_drafts() only looks at this date.
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Since the changeset no longer has an auto-draft (and it is not published)
|
* Since the changeset no longer has an auto-draft (and it is not published)
|
||||||
* it is now a persistent changeset, a long-lived draft, and so any
|
* it is now a persistent changeset, a long-lived draft, and so any
|
||||||
* associated auto-draft posts should have their dates
|
* associated auto-draft posts should likewise transition into having a draft
|
||||||
* pushed out very far into the future to prevent them from ever
|
* status. These drafts will be treated differently than regular drafts in
|
||||||
* being garbage-collected.
|
* 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.
|
||||||
*/
|
*/
|
||||||
$new_post_date = gmdate( 'Y-m-d H:i:d', strtotime( '+100 years' ) );
|
$post_args['post_status'] = 'draft';
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = json_decode( $post->post_content, true );
|
|
||||||
if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
|
foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
|
||||||
if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
|
if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$wpdb->update(
|
$wpdb->update(
|
||||||
$wpdb->posts,
|
$wpdb->posts,
|
||||||
array( 'post_date' => $new_post_date ), // Note wp_delete_auto_drafts() only looks at this date.
|
$post_args,
|
||||||
array( 'ID' => $post_id )
|
array( 'ID' => $post_id )
|
||||||
);
|
);
|
||||||
clean_post_cache( $post_id );
|
clean_post_cache( $post_id );
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.9-beta2-41886';
|
$wp_version = '4.9-beta2-41887';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue