Make WordPress Core

Ticket #38539: 38539.1.diff

File 38539.1.diff, 3.4 KB (added by westonruter, 8 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 ec0fa8d..1c80ce0 100644
    final class WP_Customize_Manager { 
    959959                // Posts & pages.
    960960                if ( ! empty( $posts ) ) {
    961961                        foreach ( array_keys( $posts ) as $post_symbol ) {
    962                                 $posts[ $post_symbol ]['ID'] = wp_insert_post( wp_slash( array_merge(
    963                                         $posts[ $post_symbol ],
    964                                         array( 'post_status' => 'auto-draft' )
    965                                 ) ) );
     962                                $r = $this->nav_menus->insert_auto_draft_post( $posts[ $post_symbol ] );
     963                                if ( $r instanceof WP_Post ) {
     964                                        $posts[ $post_symbol ]['ID'] = $r->ID;
     965                                }
    966966                        }
    967967                        $this->set_post_value( 'nav_menus_created_posts', wp_list_pluck( $posts, 'ID' ) ); // This is why nav_menus component is dependency for adding posts.
    968968                }
  • 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 ec60c2f..b337497 100644
    final class WP_Customize_Nav_Menus { 
    734734         * @since 4.7.0
    735735         *
    736736         * @param array $postarr {
    737          *     Abbreviated post array.
     737         *     Post array. Note that post_status is overridden to be `auto-draft`.
    738738         *
    739          *     @var string $post_title Post title.
    740          *     @var string $post_type  Post type.
     739         *     @var string $post_title   Post title.
     740         *     @var string $post_type    Post type.
     741         *     @var string $post_name    Post name.
     742         *     @var string $post_content Post content.
    741743         * }
    742744         * @return WP_Post|WP_Error Inserted auto-draft post object or error.
    743745         */
    final class WP_Customize_Nav_Menus { 
    745747                if ( ! isset( $postarr['post_type'] ) || ! post_type_exists( $postarr['post_type'] )  ) {
    746748                        return new WP_Error( 'unknown_post_type', __( 'Unknown post type' ) );
    747749                }
    748                 if ( ! isset( $postarr['post_title'] ) ) {
    749                         $postarr['post_title'] = '';
     750                if ( empty( $postarr['post_title'] ) ) {
     751                        return new WP_Error( 'empty_title', __( 'Empty title' ) );
     752                }
     753                if ( ! empty( $postarr['post_status'] ) ) {
     754                        return new WP_Error( 'status_forbidden', __( 'Status is forbidden' ) );
     755                }
     756
     757                $postarr['post_status'] = 'auto-draft';
     758
     759                // Auto-drafts are allowed to have empty post_names, so it has to be explicitly set.
     760                if ( ! isset( $postarr['post_name'] ) ) {
     761                        $postarr['post_name'] = sanitize_title( $postarr['post_title'] );
    750762                }
    751763
    752764                add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 );
    753                 $args = array(
    754                         'post_status' => 'auto-draft',
    755                         'post_type'   => $postarr['post_type'],
    756                         'post_title'  => $postarr['post_title'],
    757                         'post_name'   => sanitize_title( $postarr['post_title'] ), // Auto-drafts are allowed to have empty post_names, so we need to explicitly set it.
    758                 );
    759                 $r = wp_insert_post( wp_slash( $args ), true );
     765                $r = wp_insert_post( wp_slash( $postarr ), true );
    760766                remove_filter( 'wp_insert_post_empty_content', '__return_false', 1000 );
    761767
    762768                if ( is_wp_error( $r ) ) {
    final class WP_Customize_Nav_Menus { 
    11391145                $post_ids = $setting->post_value();
    11401146                if ( ! empty( $post_ids ) ) {
    11411147                        foreach ( $post_ids as $post_id ) {
    1142                                 wp_publish_post( $post_id );
     1148                                // Note that wp_publish_post() cannot be used because unique slugs need to be assigned.
     1149                                wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish' ) );
    11431150                        }
    11441151                }
    11451152        }