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
This commit is contained in:
Dion Hulse 2017-02-21 07:02:34 +00:00
parent f5b00a1534
commit 02789248ca
3 changed files with 9 additions and 3 deletions

View File

@ -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 ) {

View File

@ -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'] ) ) {

View File

@ -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.