diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
index f80708a23f..ec27563b61 100644
|
|
final class WP_Customize_Manager { |
997 | 997 | wp_list_pluck( $posts, 'post_name' ) |
998 | 998 | ); |
999 | 999 | |
| 1000 | /* |
| 1001 | * Obtain all post types referenced in starter content to use in query. |
| 1002 | * This is needed because 'any' will not account for post types not yet registered. |
| 1003 | */ |
| 1004 | $post_types = array_filter( array_merge( array( 'attachment' ), wp_list_pluck( $posts, 'post_type' ) ) ); |
| 1005 | |
1000 | 1006 | // Re-use auto-draft starter content posts referenced in the current customized state. |
1001 | 1007 | $existing_starter_content_posts = array(); |
1002 | 1008 | if ( ! empty( $starter_content_auto_draft_post_ids ) ) { |
1003 | 1009 | $existing_posts_query = new WP_Query( array( |
1004 | 1010 | 'post__in' => $starter_content_auto_draft_post_ids, |
1005 | 1011 | 'post_status' => 'auto-draft', |
1006 | | 'post_type' => 'any', |
| 1012 | 'post_type' => $post_types, |
1007 | 1013 | 'posts_per_page' => -1, |
1008 | 1014 | ) ); |
1009 | 1015 | foreach ( $existing_posts_query->posts as $existing_post ) { |
diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php
index 28e8196917..998270271d 100644
|
|
final class WP_Customize_Nav_Menus { |
786 | 786 | * @return WP_Post|WP_Error Inserted auto-draft post object or error. |
787 | 787 | */ |
788 | 788 | public function insert_auto_draft_post( $postarr ) { |
789 | | if ( ! isset( $postarr['post_type'] ) || ! post_type_exists( $postarr['post_type'] ) ) { |
| 789 | if ( ! isset( $postarr['post_type'] ) ) { |
790 | 790 | return new WP_Error( 'unknown_post_type', __( 'Invalid post type.' ) ); |
791 | 791 | } |
792 | 792 | if ( empty( $postarr['post_title'] ) ) { |
diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php
index 033fa49731..4590772ddc 100644
|
|
class Tests_WP_Customize_Manager extends WP_UnitTestCase { |
373 | 373 | 'post_title' => 'Custom', |
374 | 374 | 'thumbnail' => '{{waffles}}', |
375 | 375 | ), |
| 376 | 'unknown_cpt' => array( |
| 377 | 'post_type' => 'unknown_cpt', |
| 378 | 'post_title' => 'Unknown CPT', |
| 379 | ), |
376 | 380 | ), |
377 | 381 | 'attachments' => array( |
378 | 382 | 'waffles' => array( |
… |
… |
class Tests_WP_Customize_Manager extends WP_UnitTestCase { |
441 | 445 | $this->assertEquals( array( 'text-2', 'meta-3' ), $changeset_values['sidebars_widgets[sidebar-1]'] ); |
442 | 446 | |
443 | 447 | $posts_by_name = array(); |
444 | | $this->assertCount( 6, $changeset_values['nav_menus_created_posts'] ); |
| 448 | $this->assertCount( 7, $changeset_values['nav_menus_created_posts'] ); |
445 | 449 | $this->assertContains( $existing_published_home_page_id, $changeset_values['nav_menus_created_posts'], 'Expected reuse of non-auto-draft posts.' ); |
446 | 450 | $this->assertContains( $existing_canola_attachment_id, $changeset_values['nav_menus_created_posts'], 'Expected reuse of non-auto-draft attachment.' ); |
447 | 451 | $this->assertNotContains( $existing_auto_draft_about_page_id, $changeset_values['nav_menus_created_posts'], 'Expected non-reuse of auto-draft posts.' ); |
… |
… |
class Tests_WP_Customize_Manager extends WP_UnitTestCase { |
461 | 465 | } |
462 | 466 | $posts_by_name[ $post_name ] = $post->ID; |
463 | 467 | } |
464 | | $this->assertEquals( array( 'waffles', 'canola', 'home', 'about', 'blog', 'custom' ), array_keys( $posts_by_name ) ); |
| 468 | $this->assertEquals( array( 'waffles', 'canola', 'home', 'about', 'blog', 'custom', 'unknown-cpt' ), array_keys( $posts_by_name ) ); |
465 | 469 | $this->assertEquals( 'Custom', get_post( $posts_by_name['custom'] )->post_title ); |
466 | 470 | $this->assertEquals( 'sample-page-template.php', get_page_template_slug( $posts_by_name['about'] ) ); |
467 | 471 | $this->assertEquals( '', get_page_template_slug( $posts_by_name['blog'] ) ); |
diff --git tests/phpunit/tests/customize/nav-menus.php tests/phpunit/tests/customize/nav-menus.php
index e68ab0539a..77116305e2 100644
|
|
class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { |
538 | 538 | $this->assertInstanceOf( 'WP_Error', $r ); |
539 | 539 | $this->assertEquals( 'unknown_post_type', $r->get_error_code() ); |
540 | 540 | |
541 | | $r = $menus->insert_auto_draft_post( array( 'post_type' => 'fake' ) ); |
| 541 | // Non-existent post types allowed as of #39610. |
| 542 | $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Non-existent', 'post_type' => 'nonexistent' ) ); |
| 543 | $this->assertInstanceOf( 'WP_Post', $r ); |
| 544 | |
| 545 | $r = $menus->insert_auto_draft_post( array( 'post_type' => 'post' ) ); |
542 | 546 | $this->assertInstanceOf( 'WP_Error', $r ); |
543 | | $this->assertEquals( 'unknown_post_type', $r->get_error_code() ); |
| 547 | $this->assertEquals( 'empty_title', $r->get_error_code() ); |
544 | 548 | |
545 | 549 | $r = $menus->insert_auto_draft_post( array( 'post_status' => 'publish', 'post_title' => 'Bad', 'post_type' => 'post' ) ); |
546 | 550 | $this->assertInstanceOf( 'WP_Error', $r ); |