mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-06 21:54:28 +00:00
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:
@@ -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
|
||||
* 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
|
||||
* 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
|
||||
* @access private
|
||||
* @see wp_delete_auto_drafts()
|
||||
@@ -3078,34 +3086,55 @@ function _wp_keep_alive_customize_changeset_dependent_auto_drafts( $new_status,
|
||||
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 ) {
|
||||
/*
|
||||
* Keep the post date for the post matching 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 {
|
||||
/*
|
||||
* 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
|
||||
* associated auto-draft posts should have their dates
|
||||
* pushed out very far into the future to prevent them from ever
|
||||
* being garbage-collected.
|
||||
* 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.
|
||||
*/
|
||||
$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 ) {
|
||||
if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
|
||||
continue;
|
||||
}
|
||||
$wpdb->update(
|
||||
$wpdb->posts,
|
||||
array( 'post_date' => $new_post_date ), // Note wp_delete_auto_drafts() only looks at this date.
|
||||
$post_args,
|
||||
array( 'ID' => $post_id )
|
||||
);
|
||||
clean_post_cache( $post_id );
|
||||
|
||||
Reference in New Issue
Block a user