Ticket #40807: 40807.patch
File 40807.patch, 3.9 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 95dfa79..ab25095 100644
final class WP_Customize_Manager { 1380 1380 } 1381 1381 } 1382 1382 1383 $post_relations = array(); 1384 foreach ( array_keys( $posts ) as $post_symbol ) { 1385 if( isset( $posts[ $post_symbol ]['parent'] ) ) { 1386 $post_relations[] = array( 1387 'post_id' => $posts[$post_symbol]['ID'], 1388 'post_symbol' => $post_symbol, 1389 'parent_post_symbol' => $posts[$post_symbol]['parent'], 1390 ); 1391 } 1392 } 1393 1394 // Translate the parent post symbol to an ID and assign it to the post_parent field 1395 foreach( $post_relations as $relation ) { 1396 $post_id = $relation['post_id']; 1397 $post_symbol = $relation['post_symbol']; 1398 $parent_post_symbol = $relation['parent_post_symbol']; 1399 1400 if( isset( $posts[$parent_post_symbol]['ID'] ) ) { 1401 $posts[$post_symbol]['post_parent'] = $posts[$parent_post_symbol]['ID']; 1402 wp_update_post( array( 1403 'ID' => $post_id, 1404 'post_parent' => $posts[ $post_symbol ]['post_parent'] 1405 ) ); 1406 } 1407 } 1408 1383 1409 $starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, wp_list_pluck( $posts, 'ID' ) ); 1384 1410 } 1385 1411 -
src/wp-includes/theme.php
diff --git src/wp-includes/theme.php src/wp-includes/theme.php index 89eab5f..7255190 100644
function get_theme_starter_content() { 2174 2174 'comment_status', 2175 2175 'thumbnail', 2176 2176 'template', 2177 'parent', 2177 2178 ) 2178 2179 ); 2179 2180 } 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 0b5be85..5400b1b 100644
class Tests_WP_Customize_Manager extends WP_UnitTestCase { 713 713 } 714 714 715 715 /** 716 * @ticket 40807 717 */ 718 function test_import_theme_starter_content_should_support_post_parent() { 719 wp_set_current_user( self::$admin_user_id ); 720 721 global $wp_customize; 722 $wp_customize = new WP_Customize_Manager(); 723 724 $starter_content_config = array( 725 'posts' => array( 726 'animal' => array( 727 'post_type' => 'page', 728 'post_title' => 'Animal', 729 ), 730 'bird' => array( 731 'post_type' => 'page', 732 'post_title' => 'Bird', 733 'parent' => 'animal' 734 ), 735 'fish' => array( 736 'post_type' => 'page', 737 'post_title' => 'Fish', 738 'parent' => 'animal' 739 ), 740 ), 741 ); 742 743 add_theme_support( 'starter-content', $starter_content_config ); 744 $this->assertEmpty( $wp_customize->unsanitized_post_values() ); 745 $wp_customize->import_theme_starter_content(); 746 $changeset_values = $wp_customize->unsanitized_post_values(); 747 748 $posts_by_name = array(); 749 foreach ( $changeset_values['nav_menus_created_posts'] as $post_id ) { 750 $post = get_post( $post_id ); 751 $post_name = $post->post_name; 752 if ( empty( $post_name ) ) { 753 $post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true ); 754 } 755 $posts_by_name[ $post_name ] = $post->ID; 756 } 757 758 $expected = get_post( $posts_by_name['animal'] )->ID; 759 760 $this->assertSame( $expected, get_post( $posts_by_name['bird'] )->post_parent ); 761 $this->assertSame( $expected, get_post( $posts_by_name['fish'] )->post_parent ); 762 } 763 764 /** 716 765 * Test WP_Customize_Manager::customize_preview_init(). 717 766 * 718 767 * @ticket 30937