Changeset 39395
- Timestamp:
- 11/30/2016 11:41:50 PM (8 years ago)
- Location:
- branches/4.7
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/src/wp-content/themes/twentyseventeen/template-parts/header/header-image.php
r39394 r39395 12 12 <div class="custom-header"> 13 13 14 <?php if ( has_custom_header() ) : ?> 15 <div class="custom-header-image"> 16 <?php the_custom_header_markup(); ?> 17 </div> 18 <?php endif; ?> 14 <div class="custom-header-image"> 15 <?php the_custom_header_markup(); ?> 16 </div> 19 17 20 18 <?php get_template_part( 'template-parts/header/site', 'branding' ); ?> -
branches/4.7/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
r39366 r39395 234 234 $value = $post_value; 235 235 } 236 if ( ! empty( $value ) && empty( $value['original_title'] ) ) { 237 $value['original_title'] = $this->get_original_title( (object) $value ); 238 } 236 239 } elseif ( isset( $this->value ) ) { 237 240 $value = $this->value; … … 261 264 } 262 265 266 if ( ! empty( $value ) && empty( $value['type_label'] ) ) { 267 $value['type_label'] = $this->get_type_label( (object) $value ); 268 } 269 263 270 return $value; 264 271 } … … 274 281 */ 275 282 protected function get_original_title( $item ) { 276 if ( empty( $item->object_id ) ) {277 return '';278 }279 283 $original_title = ''; 280 if ( 'post_type' === $item->type ) {284 if ( 'post_type' === $item->type && ! empty( $item->object_id ) ) { 281 285 $original_object = get_post( $item->object_id ); 282 286 if ( $original_object ) { … … 289 293 } 290 294 } 291 } elseif ( 'taxonomy' === $item->type ) {295 } elseif ( 'taxonomy' === $item->type && ! empty( $item->object_id ) ) { 292 296 $original_term_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); 293 297 if ( ! is_wp_error( $original_term_title ) ) { 294 298 $original_title = $original_term_title; 295 299 } 300 } elseif ( 'post_type_archive' === $item->type ) { 301 $original_object = get_post_type_object( $item->object ); 302 if ( $original_object ) { 303 $original_title = $original_object->labels->archives; 304 } 296 305 } 297 306 $original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) ); 298 307 return $original_title; 308 } 309 310 /** 311 * Get type label. 312 * 313 * @since 4.7.0 314 * @access protected 315 * 316 * @param object $item Nav menu item. 317 * @returns string The type label. 318 */ 319 protected function get_type_label( $item ) { 320 if ( 'post_type' === $item->type ) { 321 $object = get_post_type_object( $item->object ); 322 if ( $object ) { 323 $type_label = $object->labels->singular_name; 324 } else { 325 $type_label = $item->object; 326 } 327 } elseif ( 'taxonomy' === $item->type ) { 328 $object = get_taxonomy( $item->object ); 329 if ( $object ) { 330 $type_label = $object->labels->singular_name; 331 } else { 332 $type_label = $item->object; 333 } 334 } elseif ( 'post_type_archive' === $item->type ) { 335 $type_label = __( 'Post Type Archive' ); 336 } else { 337 $type_label = __( 'Custom Link' ); 338 } 339 return $type_label; 299 340 } 300 341 … … 585 626 586 627 if ( ! isset( $post->type_label ) ) { 587 if ( 'post_type' === $post->type ) { 588 $object = get_post_type_object( $post->object ); 589 if ( $object ) { 590 $post->type_label = $object->labels->singular_name; 591 } else { 592 $post->type_label = $post->object; 593 } 594 } elseif ( 'taxonomy' === $post->type ) { 595 $object = get_taxonomy( $post->object ); 596 if ( $object ) { 597 $post->type_label = $object->labels->singular_name; 598 } else { 599 $post->type_label = $post->object; 600 } 601 } else { 602 $post->type_label = __( 'Custom Link' ); 603 } 628 $post->type_label = $this->get_type_label( $post ); 604 629 } 605 630 -
branches/4.7/tests/phpunit/tests/customize/nav-menu-item-setting.php
r39366 r39395 812 812 $setting->preview(); 813 813 814 $item_value = $setting->value(); 815 $this->assertArrayHasKey( 'type_label', $item_value ); 814 816 $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); 815 817 $this->assertEquals( 'Custom Link', $nav_menu_item->type_label ); 818 $this->assertEquals( $item_value['type_label'], $nav_menu_item->type_label ); 816 819 add_filter( 'wp_setup_nav_menu_item', array( $this, 'filter_type_label' ) ); 817 820 $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); … … 896 899 897 900 /** 901 * Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() for obtaining original title. 902 * 903 * @ticket 38945 904 * @covers WP_Customize_Nav_Menu_Item_Setting::get_original_title() 905 */ 906 function test_get_original_title() { 907 $menu_id = wp_create_nav_menu( 'Menu' ); 908 register_post_type( 'press_release', array( 909 'has_archive' => true, 910 'labels' => array( 911 'name' => 'PRs', 912 'singular_name' => 'PR', 913 'archives' => 'All PRs', 914 ), 915 ) ); 916 $original_post_title = 'The PR Post'; 917 $post_id = self::factory()->post->create( array( 'post_type' => 'press_release', 'post_title' => $original_post_title ) ); 918 $original_term_title = 'The Category Term'; 919 $term_id = self::factory()->term->create( array( 'taxonomy' => 'category', 'name' => $original_term_title ) ); 920 921 // Post: existing nav menu item. 922 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 923 'menu-item-object-id' => $post_id, 924 'menu-item-type' => 'post_type', 925 'menu-item-object' => 'press_release', 926 'menu-item-title' => '', 927 'menu-item-status' => 'publish', 928 ) ); 929 $setting = new WP_Customize_Nav_Menu_Item_Setting( 930 $this->wp_customize, 931 'nav_menu_item[' . $nav_menu_item_id . ']' 932 ); 933 $item_value = $setting->value(); 934 $this->assertEquals( $original_post_title, $item_value['original_title'] ); 935 $this->assertEquals( '', $item_value['title'] ); 936 $item = $setting->value_as_wp_post_nav_menu_item(); 937 $this->assertObjectHasAttribute( 'type_label', $item ); 938 $this->assertEquals( $original_post_title, $item->original_title ); 939 $this->assertEquals( $original_post_title, $item->title ); 940 $this->assertArrayHasKey( 'type_label', $item_value ); 941 $this->assertEquals( get_post_type_object( 'press_release' )->labels->singular_name, $item_value['type_label'] ); 942 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 943 944 // Post: staged nav menu item. 945 $setting = new WP_Customize_Nav_Menu_Item_Setting( 946 $this->wp_customize, 947 'nav_menu_item[-1]' 948 ); 949 $this->wp_customize->set_post_value( $setting->id, array( 950 'object_id' => $post_id, 951 'type' => 'post_type', 952 'object' => 'press_release', 953 'title' => '', 954 'status' => 'publish', 955 ) ); 956 $setting->preview(); 957 $item_value = $setting->value(); 958 $this->assertEquals( $original_post_title, $item_value['original_title'] ); 959 $this->assertEquals( '', $item_value['title'] ); 960 $item = $setting->value_as_wp_post_nav_menu_item(); 961 $this->assertObjectHasAttribute( 'type_label', $item ); 962 $this->assertEquals( $original_post_title, $item->original_title ); 963 $this->assertEquals( $original_post_title, $item->title ); 964 $this->assertArrayHasKey( 'type_label', $item_value ); 965 $this->assertEquals( get_post_type_object( 'press_release' )->labels->singular_name, $item_value['type_label'] ); 966 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 967 968 // Term: existing nav menu item. 969 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 970 'menu-item-object-id' => $term_id, 971 'menu-item-type' => 'taxonomy', 972 'menu-item-object' => 'category', 973 'menu-item-title' => '', 974 'menu-item-status' => 'publish', 975 ) ); 976 $setting = new WP_Customize_Nav_Menu_Item_Setting( 977 $this->wp_customize, 978 'nav_menu_item[' . $nav_menu_item_id . ']' 979 ); 980 $item_value = $setting->value(); 981 $this->assertEquals( $original_term_title, $item_value['original_title'] ); 982 $this->assertEquals( '', $item_value['title'] ); 983 $item = $setting->value_as_wp_post_nav_menu_item(); 984 $this->assertObjectHasAttribute( 'type_label', $item ); 985 $this->assertEquals( $original_term_title, $item->original_title ); 986 $this->assertEquals( $original_term_title, $item->title ); 987 $this->assertArrayHasKey( 'type_label', $item_value ); 988 $this->assertEquals( get_taxonomy( 'category' )->labels->singular_name, $item_value['type_label'] ); 989 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 990 991 // Term: staged nav menu item. 992 $setting = new WP_Customize_Nav_Menu_Item_Setting( 993 $this->wp_customize, 994 'nav_menu_item[-2]' 995 ); 996 $this->wp_customize->set_post_value( $setting->id, array( 997 'object_id' => $term_id, 998 'type' => 'taxonomy', 999 'object' => 'category', 1000 'title' => '', 1001 'status' => 'publish', 1002 ) ); 1003 $setting->preview(); 1004 $item_value = $setting->value(); 1005 $this->assertEquals( $original_term_title, $item_value['original_title'] ); 1006 $this->assertEquals( '', $item_value['title'] ); 1007 $item = $setting->value_as_wp_post_nav_menu_item(); 1008 $this->assertObjectHasAttribute( 'type_label', $item ); 1009 $this->assertEquals( $original_term_title, $item->original_title ); 1010 $this->assertEquals( $original_term_title, $item->title ); 1011 $this->assertArrayHasKey( 'type_label', $item_value ); 1012 $this->assertEquals( get_taxonomy( 'category' )->labels->singular_name, $item_value['type_label'] ); 1013 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 1014 1015 // Post Type Archive: existing nav menu item. 1016 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 1017 'menu-item-type' => 'post_type_archive', 1018 'menu-item-object' => 'press_release', 1019 'menu-item-title' => '', 1020 'menu-item-status' => 'publish', 1021 ) ); 1022 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1023 $this->wp_customize, 1024 'nav_menu_item[' . $nav_menu_item_id . ']' 1025 ); 1026 $item_value = $setting->value(); 1027 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] ); 1028 $this->assertEquals( '', $item_value['title'] ); 1029 $item = $setting->value_as_wp_post_nav_menu_item(); 1030 $this->assertObjectHasAttribute( 'type_label', $item ); 1031 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item->original_title ); 1032 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item->title ); 1033 $this->assertArrayHasKey( 'type_label', $item_value ); 1034 $this->assertEquals( __( 'Post Type Archive' ), $item_value['type_label'] ); 1035 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 1036 1037 // Post Type Archive: staged nav menu item. 1038 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1039 $this->wp_customize, 1040 'nav_menu_item[-3]' 1041 ); 1042 $this->wp_customize->set_post_value( $setting->id, array( 1043 'type' => 'post_type_archive', 1044 'object' => 'press_release', 1045 'title' => '', 1046 'status' => 'publish', 1047 ) ); 1048 $setting->preview(); 1049 $item_value = $setting->value(); 1050 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] ); 1051 $this->assertEquals( '', $item_value['title'] ); 1052 $item = $setting->value_as_wp_post_nav_menu_item(); 1053 $this->assertObjectHasAttribute( 'type_label', $item ); 1054 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item->original_title ); 1055 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item->title ); 1056 $this->assertArrayHasKey( 'type_label', $item_value ); 1057 $this->assertEquals( __( 'Post Type Archive' ), $item_value['type_label'] ); 1058 $this->assertEquals( $item->type_label, $item_value['type_label'] ); 1059 } 1060 1061 /** 898 1062 * Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() where title is empty. 899 1063 *
Note: See TracChangeset
for help on using the changeset viewer.