Changeset 39276
- Timestamp:
- 11/17/2016 08:17:57 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-manager.php
r39272 r39276 896 896 * @var array 897 897 */ 898 protected $ starter_content_settings_ids = array();898 protected $pending_starter_content_settings_ids = array(); 899 899 900 900 /** … … 954 954 if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) { 955 955 $this->set_post_value( $setting_id, $setting_value ); 956 $this-> starter_content_settings_ids[] = $setting_id;956 $this->pending_starter_content_settings_ids[] = $setting_id; 957 957 } 958 958 $sidebar_widget_ids[] = $widget_id; … … 962 962 if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) { 963 963 $this->set_post_value( $setting_id, $sidebar_widget_ids ); 964 $this-> starter_content_settings_ids[] = $setting_id;964 $this->pending_starter_content_settings_ids[] = $setting_id; 965 965 } 966 966 } … … 1016 1016 $nav_menus_created_posts = array_unique( array_merge( $nav_menus_created_posts, wp_list_pluck( $posts, 'ID' ) ) ); 1017 1017 $this->set_post_value( $setting_id, array_values( $nav_menus_created_posts ) ); 1018 $this-> starter_content_settings_ids[] = $setting_id;1018 $this->pending_starter_content_settings_ids[] = $setting_id; 1019 1019 } 1020 1020 } … … 1057 1057 'name' => isset( $nav_menu['name'] ) ? $nav_menu['name'] : $nav_menu_location, 1058 1058 ) ); 1059 $this-> starter_content_settings_ids[] = $nav_menu_setting_id;1059 $this->pending_starter_content_settings_ids[] = $nav_menu_setting_id; 1060 1060 1061 1061 // @todo Add support for menu_item_parent. … … 1084 1084 if ( empty( $changeset_data[ $nav_menu_item_setting_id ] ) || ! empty( $changeset_data[ $nav_menu_item_setting_id ]['starter_content'] ) ) { 1085 1085 $this->set_post_value( $nav_menu_item_setting_id, $nav_menu_item ); 1086 $this-> starter_content_settings_ids[] = $nav_menu_item_setting_id;1086 $this->pending_starter_content_settings_ids[] = $nav_menu_item_setting_id; 1087 1087 } 1088 1088 } … … 1091 1091 if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) { 1092 1092 $this->set_post_value( $setting_id, $nav_menu_term_id ); 1093 $this-> starter_content_settings_ids[] = $setting_id;1093 $this->pending_starter_content_settings_ids[] = $setting_id; 1094 1094 } 1095 1095 } … … 1103 1103 if ( empty( $changeset_data[ $name ] ) || ! empty( $changeset_data[ $name ]['starter_content'] ) ) { 1104 1104 $this->set_post_value( $name, $value ); 1105 $this-> starter_content_settings_ids[] = $name;1105 $this->pending_starter_content_settings_ids[] = $name; 1106 1106 } 1107 1107 } … … 1115 1115 if ( empty( $changeset_data[ $name ] ) || ! empty( $changeset_data[ $name ]['starter_content'] ) ) { 1116 1116 $this->set_post_value( $name, $value ); 1117 $this-> starter_content_settings_ids[] = $name;1118 } 1119 } 1120 1121 if ( ! empty( $this-> starter_content_settings_ids ) ) {1117 $this->pending_starter_content_settings_ids[] = $name; 1118 } 1119 } 1120 1121 if ( ! empty( $this->pending_starter_content_settings_ids ) ) { 1122 1122 if ( did_action( 'customize_register' ) ) { 1123 1123 $this->_save_starter_content_changeset(); … … 1136 1136 public function _save_starter_content_changeset() { 1137 1137 1138 if ( empty( $this-> starter_content_settings_ids ) ) {1138 if ( empty( $this->pending_starter_content_settings_ids ) ) { 1139 1139 return; 1140 1140 } 1141 1141 1142 1142 $this->save_changeset_post( array( 1143 'data' => array_fill_keys( $this-> starter_content_settings_ids, array( 'starter_content' => true ) ),1143 'data' => array_fill_keys( $this->pending_starter_content_settings_ids, array( 'starter_content' => true ) ), 1144 1144 'starter_content' => true, 1145 1145 ) ); 1146 1147 $this->pending_starter_content_settings_ids = array(); 1146 1148 } 1147 1149 -
trunk/src/wp-includes/theme.php
r39272 r39276 1825 1825 function get_theme_starter_content() { 1826 1826 $theme_support = get_theme_support( 'starter-content' ); 1827 if ( ! empty( $theme_support) ) {1827 if ( is_array( $theme_support ) && ! empty( $theme_support[0] ) && is_array( $theme_support[0] ) ) { 1828 1828 $config = $theme_support[0]; 1829 1829 } else { -
trunk/tests/phpunit/tests/customize/manager.php
r39181 r39276 164 164 $this->assertContains( 'Invalid changeset UUID', $exception->getMessage() ); 165 165 166 update_option( 'fresh_site', 0 ); 166 167 $wp_customize = new WP_Customize_Manager(); 167 168 $wp_customize->setup_theme(); 169 $this->assertFalse( has_action( 'after_setup_theme', array( $wp_customize, 'import_theme_starter_content' ) ) ); 170 171 // Make sure that starter content import gets queued on a fresh site. 172 update_option( 'fresh_site', 1 ); 173 $wp_customize->setup_theme(); 174 $this->assertEquals( 100, has_action( 'after_setup_theme', array( $wp_customize, 'import_theme_starter_content' ) ) ); 168 175 } 169 176 … … 297 304 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 298 305 $this->assertEquals( $data, $wp_customize->changeset_data() ); 306 } 307 308 /** 309 * Test WP_Customize_Manager::import_theme_starter_content(). 310 * 311 * @covers WP_Customize_Manager::import_theme_starter_content() 312 * @covers WP_Customize_Manager::_save_starter_content_changeset() 313 */ 314 function test_import_theme_starter_content() { 315 wp_set_current_user( self::$admin_user_id ); 316 317 global $wp_customize; 318 $wp_customize = new WP_Customize_Manager(); 319 $starter_content_config = array( 320 'widgets' => array( 321 'sidebar-1' => array( 322 'text_business_info', 323 'meta_custom' => array( 'meta', array( 324 'title' => 'Pre-hydrated meta widget.', 325 ) ), 326 ), 327 ), 328 'nav_menus' => array( 329 'top' => array( 330 'name' => 'Menu Name', 331 'items' => array( 332 'page_home', 333 'page_about', 334 'page_blog', 335 'link_email', 336 'link_facebook', 337 'link_custom' => array( 338 'title' => 'Custom', 339 'url' => 'https://custom.example.com/', 340 ), 341 ), 342 ), 343 ), 344 'posts' => array( 345 'home', 346 'about', 347 'blog', 348 'custom' => array( 349 'post_type' => 'post', 350 'post_title' => 'Custom', 351 ), 352 ), 353 'options' => array( 354 'blogname' => 'Starter Content Title', 355 'blogdescription' => 'Starter Content Tagline', 356 'show_on_front' => 'page', 357 'page_on_front' => '{{home}}', 358 'page_for_posts' => '{{blog}}', 359 ), 360 ); 361 362 add_theme_support( 'starter-content', $starter_content_config ); 363 $this->assertEmpty( $wp_customize->unsanitized_post_values() ); 364 $wp_customize->import_theme_starter_content(); 365 $changeset_values = $wp_customize->unsanitized_post_values(); 366 $expected_setting_ids = array( 367 'blogname', 368 'blogdescription', 369 'widget_text[2]', 370 'widget_meta[3]', 371 'sidebars_widgets[sidebar-1]', 372 'nav_menus_created_posts', 373 'nav_menu[-1]', 374 'nav_menu_item[-1]', 375 'nav_menu_item[-2]', 376 'nav_menu_item[-3]', 377 'nav_menu_item[-4]', 378 'nav_menu_item[-5]', 379 'nav_menu_item[-6]', 380 'nav_menu_locations[top]', 381 'show_on_front', 382 'page_on_front', 383 'page_for_posts', 384 ); 385 $this->assertEqualSets( $expected_setting_ids, array_keys( $changeset_values ) ); 386 387 foreach ( array( 'widget_text[2]', 'widget_meta[3]' ) as $setting_id ) { 388 $this->assertInternalType( 'array', $changeset_values[ $setting_id ] ); 389 $instance_data = $wp_customize->widgets->sanitize_widget_instance( $changeset_values[ $setting_id ] ); 390 $this->assertInternalType( 'array', $instance_data ); 391 $this->assertArrayHasKey( 'title', $instance_data ); 392 } 393 394 $this->assertEquals( array( 'text-2', 'meta-3' ), $changeset_values['sidebars_widgets[sidebar-1]'] ); 395 396 $posts_by_name = array(); 397 foreach ( $changeset_values['nav_menus_created_posts'] as $post_id ) { 398 $post = get_post( $post_id ); 399 $this->assertEquals( 'auto-draft', $post->post_status ); 400 $posts_by_name[ $post->post_name ] = $post->ID; 401 } 402 403 $this->assertEquals( 'page', $changeset_values['show_on_front'] ); 404 $this->assertEquals( $posts_by_name['home'], $changeset_values['page_on_front'] ); 405 $this->assertEquals( $posts_by_name['blog'], $changeset_values['page_for_posts'] ); 406 407 $this->assertEquals( -1, $changeset_values['nav_menu_locations[top]'] ); 408 $this->assertEquals( $posts_by_name['home'], $changeset_values['nav_menu_item[-1]']['object_id'] ); 409 410 $this->assertEmpty( $wp_customize->changeset_data() ); 411 $this->assertNull( $wp_customize->changeset_post_id() ); 412 $this->assertEquals( 1000, has_action( 'customize_register', array( $wp_customize, '_save_starter_content_changeset' ) ) ); 413 do_action( 'customize_register', $wp_customize ); // This will trigger the changeset save. 414 $this->assertInternalType( 'int', $wp_customize->changeset_post_id() ); 415 $this->assertNotEmpty( $wp_customize->changeset_data() ); 416 foreach ( $wp_customize->changeset_data() as $setting_id => $setting_params ) { 417 $this->assertArrayHasKey( 'starter_content', $setting_params ); 418 $this->assertTrue( $setting_params['starter_content'] ); 419 } 420 421 // Test that saving non-starter content on top of the changeset clears the starter_content flag. 422 $wp_customize->save_changeset_post( array( 423 'data' => array( 424 'blogname' => array( 'value' => 'Starter Content Modified' ), 425 ), 426 ) ); 427 $changeset_data = $wp_customize->changeset_data(); 428 $this->assertArrayNotHasKey( 'starter_content', $changeset_data['blogname'] ); 429 $this->assertArrayHasKey( 'starter_content', $changeset_data['blogdescription'] ); 430 431 // Test that adding blogname starter content is ignored now that it is modified, but updating a non-modified starter content blog description passes. 432 $previous_blogname = $changeset_data['blogname']['value']; 433 $previous_blogdescription = $changeset_data['blogdescription']['value']; 434 $wp_customize->import_theme_starter_content( array( 435 'options' => array( 436 'blogname' => 'Newer Starter Content Title', 437 'blogdescription' => 'Newer Starter Content Description', 438 ), 439 ) ); 440 $changeset_data = $wp_customize->changeset_data(); 441 $this->assertEquals( $previous_blogname, $changeset_data['blogname']['value'] ); 442 $this->assertArrayNotHasKey( 'starter_content', $changeset_data['blogname'] ); 443 $this->assertNotEquals( $previous_blogdescription, $changeset_data['blogdescription']['value'] ); 444 $this->assertArrayHasKey( 'starter_content', $changeset_data['blogdescription'] ); 299 445 } 300 446
Note: See TracChangeset
for help on using the changeset viewer.