From 02789248ca9623d45640e1ede464431d81c83e97 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 21 Feb 2017 07:02:34 +0000 Subject: [PATCH] Customize: Allow custom post types to be used in starter content. Changes `WP_Customize_Nav_Menus::insert_auto_draft_post()` so it can be invoked for a `post_type` that is not registered (yet). Props westonruter. Merges [39924] to the 4.7 branch. See #38615, #38114. Fixes #39610. Built from https://develop.svn.wordpress.org/branches/4.7@40098 git-svn-id: http://core.svn.wordpress.org/branches/4.7@40035 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-customize-manager.php | 8 +++++++- wp-includes/class-wp-customize-nav-menus.php | 2 +- wp-includes/version.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index 7f3e5a5b2d..1b2d29dc3b 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -997,13 +997,19 @@ final class WP_Customize_Manager { wp_list_pluck( $posts, 'post_name' ) ); + /* + * Obtain all post types referenced in starter content to use in query. + * This is needed because 'any' will not account for post types not yet registered. + */ + $post_types = array_filter( array_merge( array( 'attachment' ), wp_list_pluck( $posts, 'post_type' ) ) ); + // Re-use auto-draft starter content posts referenced in the current customized state. $existing_starter_content_posts = array(); if ( ! empty( $starter_content_auto_draft_post_ids ) ) { $existing_posts_query = new WP_Query( array( 'post__in' => $starter_content_auto_draft_post_ids, 'post_status' => 'auto-draft', - 'post_type' => 'any', + 'post_type' => $post_types, 'posts_per_page' => -1, ) ); foreach ( $existing_posts_query->posts as $existing_post ) { diff --git a/wp-includes/class-wp-customize-nav-menus.php b/wp-includes/class-wp-customize-nav-menus.php index e3e9233ade..dc5db7d5dd 100644 --- a/wp-includes/class-wp-customize-nav-menus.php +++ b/wp-includes/class-wp-customize-nav-menus.php @@ -786,7 +786,7 @@ final class WP_Customize_Nav_Menus { * @return WP_Post|WP_Error Inserted auto-draft post object or error. */ public function insert_auto_draft_post( $postarr ) { - if ( ! isset( $postarr['post_type'] ) || ! post_type_exists( $postarr['post_type'] ) ) { + if ( ! isset( $postarr['post_type'] ) ) { return new WP_Error( 'unknown_post_type', __( 'Unknown post type' ) ); } if ( empty( $postarr['post_title'] ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 775bb8e756..072fbfa466 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7.3-alpha-40097'; +$wp_version = '4.7.3-alpha-40098'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.