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 { |
959 | 959 | // Posts & pages. |
960 | 960 | if ( ! empty( $posts ) ) { |
961 | 961 | 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 | } |
966 | 966 | } |
967 | 967 | $this->set_post_value( 'nav_menus_created_posts', wp_list_pluck( $posts, 'ID' ) ); // This is why nav_menus component is dependency for adding posts. |
968 | 968 | } |
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 { |
734 | 734 | * @since 4.7.0 |
735 | 735 | * |
736 | 736 | * @param array $postarr { |
737 | | * Abbreviated post array. |
| 737 | * Post array. Note that post_status is overridden to be `auto-draft`. |
738 | 738 | * |
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. |
741 | 743 | * } |
742 | 744 | * @return WP_Post|WP_Error Inserted auto-draft post object or error. |
743 | 745 | */ |
… |
… |
final class WP_Customize_Nav_Menus { |
745 | 747 | if ( ! isset( $postarr['post_type'] ) || ! post_type_exists( $postarr['post_type'] ) ) { |
746 | 748 | return new WP_Error( 'unknown_post_type', __( 'Unknown post type' ) ); |
747 | 749 | } |
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'] ); |
750 | 762 | } |
751 | 763 | |
752 | 764 | 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 ); |
760 | 766 | remove_filter( 'wp_insert_post_empty_content', '__return_false', 1000 ); |
761 | 767 | |
762 | 768 | if ( is_wp_error( $r ) ) { |
… |
… |
final class WP_Customize_Nav_Menus { |
1139 | 1145 | $post_ids = $setting->post_value(); |
1140 | 1146 | if ( ! empty( $post_ids ) ) { |
1141 | 1147 | 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' ) ); |
1143 | 1150 | } |
1144 | 1151 | } |
1145 | 1152 | } |