Ticket #38015: 38015.1.diff
File 38015.1.diff, 9.8 KB (added by , 8 years ago) |
---|
-
src/wp-admin/js/customize-nav-menus.js
diff --git src/wp-admin/js/customize-nav-menus.js src/wp-admin/js/customize-nav-menus.js index e514a0a..6dcdadc 100644
1397 1397 } 1398 1398 1399 1399 var titleEl = control.container.find( '.menu-item-title' ), 1400 titleText = item.title || api.Menus.data.l10n.untitled;1400 titleText = item.title || item.original_title || api.Menus.data.l10n.untitled; 1401 1401 1402 1402 if ( item._invalid ) { 1403 1403 titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText ); 1404 1404 } 1405 1405 1406 1406 // Don't update to an empty title. 1407 if ( item.title ) {1407 if ( item.title || item.original_title ) { 1408 1408 titleEl 1409 1409 .text( titleText ) 1410 1410 .removeClass( 'no-title' ); -
src/wp-includes/class-wp-customize-nav-menus.php
diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php index f68dc13..87dcadb 100644
final class WP_Customize_Nav_Menus { 587 587 $menu_item_setting_id = 'nav_menu_item[' . $item->ID . ']'; 588 588 589 589 $value = (array) $item; 590 if ( empty( $value['post_title'] ) ) { 591 $value['title'] = ''; 592 } 593 590 594 $value['nav_menu_term_id'] = $menu_id; 591 595 $this->manager->add_setting( new WP_Customize_Nav_Menu_Item_Setting( $this->manager, $menu_item_setting_id, array( 592 596 'value' => $value, -
src/wp-includes/customize/class-wp-customize-nav-menu-item-control.php
diff --git src/wp-includes/customize/class-wp-customize-nav-menu-item-control.php src/wp-includes/customize/class-wp-customize-nav-menu-item-control.php index 95e7b54..ee3311b 100644
class WP_Customize_Nav_Menu_Item_Control extends WP_Customize_Control { 69 69 <span class="item-type" aria-hidden="true">{{ data.item_type_label }}</span> 70 70 <span class="item-title" aria-hidden="true"> 71 71 <span class="spinner"></span> 72 <span class="menu-item-title<# if ( ! data.title ) { #> no-title<# } #>">{{ data.title || wp.customize.Menus.data.l10n.untitled }}</span>72 <span class="menu-item-title<# if ( ! data.title && ! data.original_title ) { #> no-title<# } #>">{{ data.title || data.original_title || wp.customize.Menus.data.l10n.untitled }}</span> 73 73 </span> 74 74 <span class="item-controls"> 75 75 <button type="button" class="button-link item-edit" aria-expanded="false"><span class="screen-reader-text"><?php … … class WP_Customize_Nav_Menu_Item_Control extends WP_Customize_Control { 96 96 <p class="description description-thin"> 97 97 <label for="edit-menu-item-title-{{ data.menu_item_id }}"> 98 98 <?php _e( 'Navigation Label' ); ?><br /> 99 <input type="text" id="edit-menu-item-title-{{ data.menu_item_id }}" class="widefat edit-menu-item-title" name="menu-item-title" />99 <input type="text" id="edit-menu-item-title-{{ data.menu_item_id }}" placeholder="{{ data.original_title }}" class="widefat edit-menu-item-title" name="menu-item-title" /> 100 100 </label> 101 101 </p> 102 102 <p class="field-link-target description description-thin"> -
src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
diff --git src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php index c71ab09..576f3c6 100644
class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { 233 233 } else { 234 234 $value = $post_value; 235 235 } 236 } else 236 } elseif ( isset( $this->value ) ) { 237 237 $value = $this->value; 238 238 } else { 239 239 $value = false; … … class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { 242 242 if ( $this->post_id > 0 ) { 243 243 $post = get_post( $this->post_id ); 244 244 if ( $post && self::POST_TYPE === $post->post_type ) { 245 $is_title_empty = empty( $post->post_title ); 245 246 $value = (array) wp_setup_nav_menu_item( $post ); 247 if ( $is_title_empty ) { 248 $value['title'] = ''; 249 } 246 250 } 247 251 } 248 252 … … class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { 260 264 } 261 265 262 266 /** 267 * Get original title. 268 * 269 * @since 4.7.0 270 * 271 * @param object $item Nav menu item. 272 * @return string The original title. 273 */ 274 protected function get_original_title( $item ) { 275 if ( empty( $item->object_id ) ) { 276 return ''; 277 } 278 $original_title = ''; 279 if ( 'post_type' === $item->type ) { 280 $original_object = get_post( $item->object_id ); 281 if ( $original_object ) { 282 /** This filter is documented in wp-includes/post-template.php */ 283 $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID ); 284 285 if ( '' === $original_title ) { 286 /* translators: %d: ID of a post */ 287 $original_title = sprintf( __( '#%d (no title)' ), $original_object->ID ); 288 } 289 } 290 } elseif ( 'taxonomy' === $item->type ) { 291 $original_term_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); 292 if ( ! is_wp_error( $original_term_title ) ) { 293 $original_title = $original_term_title; 294 } 295 } 296 $original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) ); 297 return $original_title; 298 } 299 300 /** 263 301 * Ensure that the value is fully populated with the necessary properties. 264 302 * 265 303 * Translates some properties added by wp_setup_nav_menu_item() and removes others. … … class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { 284 322 } 285 323 286 324 if ( ! isset( $this->value['original_title'] ) ) { 287 $original_title = ''; 288 if ( 'post_type' === $this->value['type'] ) { 289 $original_title = get_the_title( $this->value['object_id'] ); 290 } elseif ( 'taxonomy' === $this->value['type'] ) { 291 $original_title = get_term_field( 'name', $this->value['object_id'], $this->value['object'], 'raw' ); 292 if ( is_wp_error( $original_title ) ) { 293 $original_title = ''; 294 } 295 } 296 $this->value['original_title'] = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) ); 325 $this->value['original_title'] = $this->get_original_title( (object) $this->value ); 297 326 } 298 327 299 328 if ( ! isset( $this->value['nav_menu_term_id'] ) && $this->post_id > 0 ) { … … class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { 534 563 $item->menu_order = $item->position; 535 564 unset( $item->position ); 536 565 566 if ( empty( $item->original_title ) ) { 567 $item->original_title = $this->get_original_title( $item ); 568 } 569 if ( empty( $item->title ) && ! empty( $item->original_title ) ) { 570 $item->title = $item->original_title; 571 } 537 572 if ( $item->title ) { 538 573 $item->post_title = $item->title; 539 574 } … … class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { 554 589 } else { 555 590 $post->type_label = $post->object; 556 591 } 557 } elseif ( 'taxonomy' == $post->type ) {592 } elseif ( 'taxonomy' === $post->type ) { 558 593 $object = get_taxonomy( $post->object ); 559 594 if ( $object ) { 560 595 $post->type_label = $object->labels->singular_name; -
tests/phpunit/tests/customize/nav-menu-item-setting.php
diff --git tests/phpunit/tests/customize/nav-menu-item-setting.php tests/phpunit/tests/customize/nav-menu-item-setting.php index 56f75a3..ebb9748 100644
class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { 185 185 } 186 186 187 187 /** 188 * Test value method with post without nav menu item title (label). 189 * 190 * @see WP_Customize_Nav_Menu_Item_Setting::value() 191 */ 192 function test_value_type_post_type_without_label() { 193 do_action( 'customize_register', $this->wp_customize ); 194 195 $original_title = 'Hello World'; 196 $post_id = self::factory()->post->create( array( 'post_title' => $original_title ) ); 197 198 $menu_id = wp_create_nav_menu( 'Menu' ); 199 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 200 'menu-item-type' => 'post_type', 201 'menu-item-object' => 'post', 202 'menu-item-object-id' => $post_id, 203 'menu-item-title' => '', 204 'menu-item-status' => 'publish', 205 ) ); 206 207 $setting_id = "nav_menu_item[$item_id]"; 208 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 209 210 $value = $setting->value(); 211 $this->assertEquals( '', $value['title'] ); 212 $this->assertEquals( $original_title, $value['original_title'] ); 213 } 214 215 /** 188 216 * Test value method with taxonomy. 189 217 * 190 218 * @see WP_Customize_Nav_Menu_Item_Setting::value() … … class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { 804 832 $this->assertEquals( $expected, $nav_menu_item->attr_title ); 805 833 $this->assertEquals( 'Attempted \o/ o’o markup', $nav_menu_item->description ); 806 834 } 835 836 /** 837 * Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() where title is empty. 838 * 839 * @ticket 38015 840 * @see WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() 841 */ 842 function test_value_as_wp_post_nav_menu_item_with_empty_title() { 843 $original_title = 'The Original Title'; 844 $post_id = self::factory()->post->create( array( 'post_title' => $original_title ) ); 845 846 $setting = new WP_Customize_Nav_Menu_Item_Setting( 847 $this->wp_customize, 848 'nav_menu_item[123]' 849 ); 850 851 $post_value = array_merge( 852 $setting->default, 853 array( 854 'object_id' => $post_id, 855 'object' => 'post', 856 'type' => 'post_type', 857 'status' => 'publish', 858 'nav_menu_term_id' => 0, 859 ) 860 ); 861 $this->wp_customize->set_post_value( $setting->id, $post_value ); 862 863 $setting->preview(); 864 865 $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); 866 $this->assertEquals( $original_title, $nav_menu_item->title ); 867 } 807 868 }