Make WordPress Core


Ignore:
Timestamp:
10/17/2017 08:14:56 PM (9 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/src/wp-includes/theme.php

    r41824 r41887  
    30523052
    30533053/**
    3054  * Make sure that auto-draft posts get their post_date bumped to prevent premature garbage-collection.
     3054 * Make sure that auto-draft posts get their post_date bumped or status changed to draft to prevent premature garbage-collection.
    30553055 *
    30563056 * When a changeset is updated but remains an auto-draft, ensure the post_date
    … …  
    30613061 * unless the changeset post itself is deleted.
    30623062 *
     3063 * When a changeset is updated to be a persistent draft or to be scheduled for
     3064 * publishing, then transition any dependent auto-drafts to a draft status so
     3065 * that they likewise will not be garbage-collected but also so that they can
     3066 * be edited in the admin before publishing since there is not yet a post/page
     3067 * editing flow in the Customizer. See #39752.
     3068 *
     3069 * @link https://core.trac.wordpress.org/ticket/39752
     3070 *
    30633071 * @since 4.8.0
    30643072 * @access private
    … …  
    30793087        }
    30803088
     3089        $data = json_decode( $post->post_content, true );
     3090        if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
     3091                return;
     3092        }
     3093
     3094        /*
     3095         * Actually, in lieu of keeping alive, trash any customization drafts here if the changeset itself is
     3096         * getting trashed. This is needed because when a changeset transitions to a draft, then any of the
     3097         * dependent auto-draft post/page stubs will also get transitioned to customization drafts which
     3098         * are then visible in the WP Admin. We cannot wait for the deletion of the changeset in which
     3099         * _wp_delete_customize_changeset_dependent_auto_drafts() will be called, since they need to be
     3100         * trashed to remove from visibility immediately.
     3101         */
     3102        if ( 'trash' === $new_status ) {
     3103                foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
     3104                        if ( ! empty( $post_id ) && 'draft' === get_post_status( $post_id ) ) {
     3105                                wp_trash_post( $post_id );
     3106                        }
     3107                }
     3108                return;
     3109        }
     3110
     3111        $post_args = array();
    30813112        if ( 'auto-draft' === $new_status ) {
    30823113                /*
    … …  
    30843115                 * so that it will not be garbage-collected before the changeset.
    30853116                 */
    3086                 $new_post_date = $post->post_date;
     3117                $post_args['post_date'] = $post->post_date; // Note wp_delete_auto_drafts() only looks at this date.
    30873118        } else {
    30883119                /*
    30893120                 * Since the changeset no longer has an auto-draft (and it is not published)
    30903121                 * it is now a persistent changeset, a long-lived draft, and so any
    3091                  * associated auto-draft posts should have their dates
    3092                  * pushed out very far into the future to prevent them from ever
    3093                  * being garbage-collected.
     3122                 * associated auto-draft posts should likewise transition into having a draft
     3123                 * status. These drafts will be treated differently than regular drafts in
     3124                 * that they will be tied to the given changeset. The publish metabox is
     3125                 * replaced with a notice about how the post is part of a set of customized changes
     3126                 * which will be published when the changeset is published.
    30943127                 */
    3095                 $new_post_date = gmdate( 'Y-m-d H:i:d', strtotime( '+100 years' ) );
    3096         }
    3097 
    3098         $data = json_decode( $post->post_content, true );
    3099         if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
    3100                 return;
    3101         }
     3128                $post_args['post_status'] = 'draft';
     3129        }
     3130
    31023131        foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
    31033132                if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
    … …  
    31063135                $wpdb->update(
    31073136                        $wpdb->posts,
    3108                         array( 'post_date' => $new_post_date ), // Note wp_delete_auto_drafts() only looks at this date.
     3137                        $post_args,
    31093138                        array( 'ID' => $post_id )
    31103139                );
Note: See TracChangeset for help on using the changeset viewer.