Ticket #40807: 40807.3.diff
File 40807.3.diff, 4.4 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-customize-manager.php
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php index 955d59eee6..45805e2f44 100644
final class WP_Customize_Manager { 1381 1381 } 1382 1382 } 1383 1383 1384 $post_relations = array(); 1385 foreach ( array_keys( $posts ) as $post_symbol ) { 1386 if ( isset( $posts[ $post_symbol ]['parent'] ) ) { 1387 $post_relations[] = array( 1388 'post_id' => $posts[ $post_symbol ]['ID'], 1389 'post_symbol' => $post_symbol, 1390 'parent_post_symbol' => $posts[ $post_symbol ]['parent'], 1391 ); 1392 } 1393 } 1394 1395 // Translate the parent post symbol to an ID and assign it to the post_parent field. 1396 foreach ( $post_relations as $relation ) { 1397 $post_id = $relation['post_id']; 1398 $post_symbol = $relation['post_symbol']; 1399 $parent_post_symbol = $relation['parent_post_symbol']; 1400 1401 if ( isset( $posts[ $parent_post_symbol ]['ID'] ) ) { 1402 $posts[ $post_symbol ]['post_parent'] = $posts[ $parent_post_symbol ]['ID']; 1403 wp_update_post( array( 1404 'ID' => $post_id, 1405 'post_parent' => $posts[ $post_symbol ]['post_parent'], 1406 ) ); 1407 } 1408 } 1409 1384 1410 $starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, wp_list_pluck( $posts, 'ID' ) ); 1385 1411 } 1386 1412 -
src/wp-includes/theme.php
diff --git src/wp-includes/theme.php src/wp-includes/theme.php index 2ee66fbddf..72ed4daa36 100644
function get_theme_starter_content() { 2175 2175 'comment_status', 2176 2176 'thumbnail', 2177 2177 'template', 2178 'parent', 2178 2179 ) 2179 2180 ); 2180 2181 } elseif ( is_string( $item ) && ! empty( $core_content[ $type ][ $item ] ) ) { -
tests/phpunit/tests/customize/manager.php
diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php index 1c1814b6a2..589ec7cb4b 100644
class Tests_WP_Customize_Manager extends WP_UnitTestCase { 740 740 $this->assertEmpty( get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) ); 741 741 } 742 742 743 /** 744 * Test import_theme_starter_content() should support post_parent. 745 * 746 * @covers WP_Customize_Manager::import_theme_starter_content() 747 * @ticket 40807 748 */ 749 public function test_import_theme_starter_content_should_support_post_parent() { 750 wp_set_current_user( self::$admin_user_id ); 751 752 global $wp_customize; 753 $wp_customize = new WP_Customize_Manager(); 754 755 $starter_content_config = array( 756 'posts' => array( 757 'animal' => array( 758 'post_type' => 'page', 759 'post_title' => 'Animal', 760 ), 761 'bird' => array( 762 'post_type' => 'page', 763 'post_title' => 'Bird', 764 'parent' => 'animal', 765 ), 766 'owl' => array( 767 'post_type' => 'page', 768 'post_title' => 'Owl', 769 'parent' => 'birds', // Non-existing post symbol that should result in post_parent as 0. 770 ), 771 'fish' => array( 772 'post_type' => 'page', 773 'post_title' => 'Fish', 774 'parent' => 'animal', 775 ), 776 'salmon' => array( 777 'post_type' => 'page', 778 'post_title' => 'Salmon', 779 'parent' => 'fish', 780 ), 781 ), 782 ); 783 784 add_theme_support( 'starter-content', $starter_content_config ); 785 $this->assertEmpty( $wp_customize->unsanitized_post_values() ); 786 $wp_customize->import_theme_starter_content(); 787 $changeset_values = $wp_customize->unsanitized_post_values(); 788 789 $posts_by_name = array(); 790 foreach ( $changeset_values['nav_menus_created_posts'] as $post_id ) { 791 $post = get_post( $post_id ); 792 $post_name = $post->post_name; 793 if ( empty( $post_name ) ) { 794 $post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true ); 795 } 796 $posts_by_name[ $post_name ] = $post->ID; 797 } 798 799 $this->assertSame( $posts_by_name['animal'], get_post_field( 'post_parent', $posts_by_name['bird'] ) ); 800 $this->assertSame( $posts_by_name['animal'], get_post_field( 'post_parent', $posts_by_name['fish'] ) ); 801 $this->assertSame( $posts_by_name['fish'], get_post_field( 'post_parent', $posts_by_name['salmon'] ) ); 802 $this->assertSame( 0, get_post_field( 'post_parent', $posts_by_name['animal'] ) ); 803 $this->assertSame( 0, get_post_field( 'post_parent', $posts_by_name['owl'] ) ); 804 } 805 743 806 /** 744 807 * Test WP_Customize_Manager::customize_preview_init(). 745 808 *