WordPress.org

Make WordPress Core

Ticket #42612: 42612.diff

File 42612.diff, 4.7 KB (added by dlh, 3 years ago)
  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index fe22d87a06..1c7e53fa39 100644
    final class WP_Customize_Manager { 
    13921392
    13931393                // Posts & pages.
    13941394                if ( ! empty( $posts ) ) {
    1395                         foreach ( array_keys( $posts ) as $post_symbol ) {
     1395                        $post_date = current_time( 'timestamp' );
     1396
     1397                        foreach ( array_keys( $posts ) as $i => $post_symbol ) {
    13961398                                if ( empty( $posts[ $post_symbol ]['post_type'] ) || empty( $posts[ $post_symbol ]['post_name'] ) ) {
    13971399                                        continue;
    13981400                                }
    final class WP_Customize_Manager { 
    14081410                                // Use existing auto-draft post if one already exists with the same type and name.
    14091411                                if ( isset( $existing_starter_content_posts[ $post_type . ':' . $post_name ] ) ) {
    14101412                                        $posts[ $post_symbol ]['ID'] = $existing_starter_content_posts[ $post_type . ':' . $post_name ]->ID;
     1413                                        update_post_meta( $posts[ $post_symbol ]['ID'], '_starter_content_theme', $this->get_stylesheet() );
    14111414                                        continue;
    14121415                                }
    14131416
    final class WP_Customize_Manager { 
    14221425                                        $posts[ $post_symbol ]['meta_input']['_wp_page_template'] = $posts[ $post_symbol ]['template'];
    14231426                                }
    14241427
     1428                                // Keep "reverse-chronological" order given where the post appeared in the starter content. See #42612.
     1429                                $posts[ $post_symbol ]['post_date'] = gmdate( 'Y-m-d H:i:s', $post_date - $i );
     1430
     1431                                // Allow this post to be identified as starter content.
     1432                                $posts[ $post_symbol ]['meta_input']['_starter_content_theme'] = $this->get_stylesheet();
     1433
    14251434                                $r = $this->nav_menus->insert_auto_draft_post( $posts[ $post_symbol ] );
    14261435                                if ( $r instanceof WP_Post ) {
    14271436                                        $posts[ $post_symbol ]['ID'] = $r->ID;
  • src/wp-includes/class-wp-customize-nav-menus.php

    diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php
    index 9529ce78a3..43fa8973ce 100644
    final class WP_Customize_Nav_Menus { 
    12761276        public function save_nav_menus_created_posts( $setting ) {
    12771277                $post_ids = $setting->post_value();
    12781278                if ( ! empty( $post_ids ) ) {
    1279                         foreach ( $post_ids as $post_id ) {
     1279                        $post_date = current_time( 'timestamp' );
    12801280
     1281                        foreach ( $post_ids as $i => $post_id ) {
    12811282                                // Prevent overriding the status that a user may have prematurely updated the post to.
    12821283                                $current_status = get_post_status( $post_id );
    12831284                                if ( 'auto-draft' !== $current_status && 'draft' !== $current_status ) {
    final class WP_Customize_Nav_Menus { 
    12941295                                        $args['post_name'] = $post_name;
    12951296                                }
    12961297
     1298                                // Publish starter content "reverse-chronologically" based on where it appeared in the theme definition. See #42612.
     1299                                if ( get_post_meta( $post_id, '_starter_content_theme', true ) ) {
     1300                                        $args['edit_date'] = true;
     1301                                        $args['post_date'] = gmdate( 'Y-m-d H:i:s', $post_date - $i );
     1302                                }
     1303
    12971304                                // Note that wp_publish_post() cannot be used because unique slugs need to be assigned.
    12981305                                wp_update_post( wp_slash( $args ) );
    12991306
  • src/wp-includes/theme.php

    diff --git src/wp-includes/theme.php src/wp-includes/theme.php
    index 406fa4a310..90e2d62e99 100644
    function is_customize_preview() { 
    31913191 *
    31923192 * When a changeset is updated but remains an auto-draft, ensure the post_date
    31933193 * for the auto-draft posts remains the same so that it will be
    3194  * garbage-collected at the same time by `wp_delete_auto_drafts()`. Otherwise,
    3195  * if the changeset is updated to be a draft then update the posts
    3196  * to have a far-future post_date so that they will never be garbage collected
    3197  * unless the changeset post itself is deleted.
     3194 * garbage-collected at the same time by `wp_delete_auto_drafts()`.
    31983195 *
    31993196 * When a changeset is updated to be a persistent draft or to be scheduled for
    32003197 * publishing, then transition any dependent auto-drafts to a draft status so
    function _wp_keep_alive_customize_changeset_dependent_auto_drafts( $new_status, 
    32643261                $post_args['post_status'] = 'draft';
    32653262        }
    32663263
    3267         foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
     3264        foreach ( $data['nav_menus_created_posts']['value'] as $i => $post_id ) {
    32683265                if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
    32693266                        continue;
    32703267                }
     3268
     3269                // Keep starter content "reverse-chronological" based on where it appeared in the theme definition. See #42612.
     3270                if ( isset( $post_args['post_date'] ) && get_post_meta( $post_id, '_starter_content_theme', true ) ) {
     3271                        $post_args['post_date'] = gmdate( 'Y-m-d H:i:s', strtotime( $post_args['post_date'] ) - $i );
     3272                }
     3273
    32713274                $wpdb->update(
    32723275                        $wpdb->posts,
    32733276                        $post_args,