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

See #38615, #38114.
Fixes #39610.

Built from https://develop.svn.wordpress.org/trunk@39924


git-svn-id: http://core.svn.wordpress.org/trunk@39861 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-01-19 00:01:46 +00:00
parent 1326d9e2c7
commit 3e6c892f89
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', __( 'Invalid post type.' ) );
}
if ( empty( $postarr['post_title'] ) ) {

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-39923';
$wp_version = '4.8-alpha-39924';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.