Make WordPress Core


Ignore:
Timestamp:
12/05/2016 07:32:09 PM (7 years ago)
Author:
westonruter
Message:

Customize: Defer populating post_name for auto-draft posts in customized state until posts are published.

The ultimate post_name is stored in postmeta until the post is published. The get_page_by_path() function does not exclude auto-draft posts. Revert changes to wp_unique_post_slug() from [39411] which excluded auto-draft posts.

Props westonruter, dlh for testing, helen for testing.
See #38114, #38928.
Fixes #39078.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r39346 r39506  
    804804            $postarr['post_name'] = sanitize_title( $postarr['post_title'] );
    805805        }
     806        if ( ! isset( $postarr['meta_input'] ) ) {
     807            $postarr['meta_input'] = array();
     808        }
     809        $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name'];
     810        unset( $postarr['post_name'] );
    806811
    807812        add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 );
     
    11931198            foreach ( $post_ids as $post_id ) {
    11941199                $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish';
     1200                $args = array(
     1201                    'ID' => $post_id,
     1202                    'post_status' => $target_status,
     1203                );
     1204                $post_name = get_post_meta( $post_id, '_customize_draft_post_name', true );
     1205                if ( $post_name ) {
     1206                    $args['post_name'] = $post_name;
     1207                }
    11951208
    11961209                // Note that wp_publish_post() cannot be used because unique slugs need to be assigned.
    1197                 wp_update_post( array( 'ID' => $post_id, 'post_status' => $target_status ) );
     1210                wp_update_post( wp_slash( $args ) );
     1211
     1212                delete_post_meta( $post_id, '_customize_draft_post_name' );
    11981213            }
    11991214        }
Note: See TracChangeset for help on using the changeset viewer.