Ticket #40807: 40807.4.diff
File 40807.4.diff, 4.5 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 955d59e..bc37704 100644
final class WP_Customize_Manager { 1381 1381 } 1382 1382 } 1383 1383 1384 // Translate the parent post symbol to an ID and assign it to the post_parent field. 1385 $post_relations = array(); 1386 foreach ( array_keys( $posts ) as $post_symbol ) { 1387 if ( ! empty( $posts[ $post_symbol ]['parent'] ) 1388 && preg_match( '/^{{(?P<symbol>.+)}}$/', $posts[ $post_symbol ]['parent'], $matches ) ) { 1389 $post_relations[] = array( 1390 'post_id' => $posts[ $post_symbol ]['ID'], 1391 'post_symbol' => $post_symbol, 1392 'parent_post_symbol' => $matches['symbol'], 1393 ); 1394 } 1395 } 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 2ee66fb..72ed4da 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 1c1814b..fcd6e56 100644
class Tests_WP_Customize_Manager extends WP_UnitTestCase { 741 741 } 742 742 743 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 'salmon' => array( 772 'post_type' => 'page', 773 'post_title' => 'Salmon', 774 'parent' => '{{fish}}', 775 ), 776 /* It shouldn't matter if the parent is defined after the child */ 777 'fish' => array( 778 'post_type' => 'page', 779 'post_title' => 'Fish', 780 'parent' => '{{animal}}', 781 ), 782 ), 783 ); 784 785 add_theme_support( 'starter-content', $starter_content_config ); 786 $this->assertEmpty( $wp_customize->unsanitized_post_values() ); 787 $wp_customize->import_theme_starter_content(); 788 $changeset_values = $wp_customize->unsanitized_post_values(); 789 790 $posts_by_name = array(); 791 foreach ( $changeset_values['nav_menus_created_posts'] as $post_id ) { 792 $post = get_post( $post_id ); 793 $post_name = $post->post_name; 794 if ( empty( $post_name ) ) { 795 $post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true ); 796 } 797 $posts_by_name[ $post_name ] = $post->ID; 798 } 799 800 $this->assertSame( $posts_by_name['animal'], get_post_field( 'post_parent', $posts_by_name['bird'] ) ); 801 $this->assertSame( $posts_by_name['animal'], get_post_field( 'post_parent', $posts_by_name['fish'] ) ); 802 $this->assertSame( $posts_by_name['fish'], get_post_field( 'post_parent', $posts_by_name['salmon'] ) ); 803 $this->assertSame( 0, get_post_field( 'post_parent', $posts_by_name['animal'] ) ); 804 $this->assertSame( 0, get_post_field( 'post_parent', $posts_by_name['owl'] ) ); 805 } 806 807 /** 744 808 * Test WP_Customize_Manager::customize_preview_init(). 745 809 * 746 810 * @ticket 30937