Permalink
Browse files

Customize: Ensure nav menu items lacking a label use the title from t…

…he original object.

Use original title as placeholder for label and in control title. Prevent original title from overriding empty label in initial setting values.

Fixes #38015.

Built from https://develop.svn.wordpress.org/trunk@38618


git-svn-id: http://core.svn.wordpress.org/trunk@38561 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
1 parent ea69657 commit 037a236e423d0a38d00767f0659b0837116dde27 @westonruter westonruter committed Sep 17, 2016
@@ -1397,14 +1397,14 @@
}
var titleEl = control.container.find( '.menu-item-title' ),
- titleText = item.title || api.Menus.data.l10n.untitled;
+ titleText = item.title || item.original_title || api.Menus.data.l10n.untitled;
if ( item._invalid ) {
titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText );
}
// Don't update to an empty title.
- if ( item.title ) {
+ if ( item.title || item.original_title ) {
titleEl
.text( titleText )
.removeClass( 'no-title' );
Oops, something went wrong.
@@ -587,6 +587,10 @@ public function customize_register() {
$menu_item_setting_id = 'nav_menu_item[' . $item->ID . ']';
$value = (array) $item;
+ if ( empty( $value['post_title'] ) ) {
+ $value['title'] = '';
+ }
+
$value['nav_menu_term_id'] = $menu_id;
$this->manager->add_setting( new WP_Customize_Nav_Menu_Item_Setting( $this->manager, $menu_item_setting_id, array(
'value' => $value,
@@ -69,7 +69,7 @@ public function content_template() {
<span class="item-type" aria-hidden="true">{{ data.item_type_label }}</span>
<span class="item-title" aria-hidden="true">
<span class="spinner"></span>
- <span class="menu-item-title<# if ( ! data.title ) { #> no-title<# } #>">{{ data.title || wp.customize.Menus.data.l10n.untitled }}</span>
+ <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>
</span>
<span class="item-controls">
<button type="button" class="button-link item-edit" aria-expanded="false"><span class="screen-reader-text"><?php
@@ -96,7 +96,7 @@ public function content_template() {
<p class="description description-thin">
<label for="edit-menu-item-title-{{ data.menu_item_id }}">
<?php _e( 'Navigation Label' ); ?><br />
- <input type="text" id="edit-menu-item-title-{{ data.menu_item_id }}" class="widefat edit-menu-item-title" name="menu-item-title" />
+ <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" />
</label>
</p>
<p class="field-link-target description description-thin">
@@ -233,7 +233,7 @@ public function value() {
} else {
$value = $post_value;
}
- } else if ( isset( $this->value ) ) {
+ } elseif ( isset( $this->value ) ) {
$value = $this->value;
} else {
$value = false;
@@ -242,7 +242,11 @@ public function value() {
if ( $this->post_id > 0 ) {
$post = get_post( $this->post_id );
if ( $post && self::POST_TYPE === $post->post_type ) {
+ $is_title_empty = empty( $post->post_title );
$value = (array) wp_setup_nav_menu_item( $post );
+ if ( $is_title_empty ) {
+ $value['title'] = '';
+ }
}
}
@@ -260,6 +264,40 @@ public function value() {
}
/**
+ * Get original title.
+ *
+ * @since 4.7.0
+ *
+ * @param object $item Nav menu item.
+ * @return string The original title.
+ */
+ protected function get_original_title( $item ) {
+ if ( empty( $item->object_id ) ) {
+ return '';
+ }
+ $original_title = '';
+ if ( 'post_type' === $item->type ) {
+ $original_object = get_post( $item->object_id );
+ if ( $original_object ) {
+ /** This filter is documented in wp-includes/post-template.php */
+ $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID );
+
+ if ( '' === $original_title ) {
+ /* translators: %d: ID of a post */
+ $original_title = sprintf( __( '#%d (no title)' ), $original_object->ID );
+ }
+ }
+ } elseif ( 'taxonomy' === $item->type ) {
+ $original_term_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
+ if ( ! is_wp_error( $original_term_title ) ) {
+ $original_title = $original_term_title;
+ }
+ }
+ $original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) );
+ return $original_title;
+ }
+
+ /**
* Ensure that the value is fully populated with the necessary properties.
*
* Translates some properties added by wp_setup_nav_menu_item() and removes others.
@@ -284,16 +322,7 @@ protected function populate_value() {
}
if ( ! isset( $this->value['original_title'] ) ) {
- $original_title = '';
- if ( 'post_type' === $this->value['type'] ) {
- $original_title = get_the_title( $this->value['object_id'] );
- } elseif ( 'taxonomy' === $this->value['type'] ) {
- $original_title = get_term_field( 'name', $this->value['object_id'], $this->value['object'], 'raw' );
- if ( is_wp_error( $original_title ) ) {
- $original_title = '';
- }
- }
- $this->value['original_title'] = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) );
+ $this->value['original_title'] = $this->get_original_title( (object) $this->value );
}
if ( ! isset( $this->value['nav_menu_term_id'] ) && $this->post_id > 0 ) {
@@ -534,6 +563,12 @@ public function value_as_wp_post_nav_menu_item() {
$item->menu_order = $item->position;
unset( $item->position );
+ if ( empty( $item->original_title ) ) {
+ $item->original_title = $this->get_original_title( $item );
+ }
+ if ( empty( $item->title ) && ! empty( $item->original_title ) ) {
+ $item->title = $item->original_title;
+ }
if ( $item->title ) {
$item->post_title = $item->title;
}
@@ -554,7 +589,7 @@ public function value_as_wp_post_nav_menu_item() {
} else {
$post->type_label = $post->object;
}
- } elseif ( 'taxonomy' == $post->type ) {
+ } elseif ( 'taxonomy' === $post->type ) {
$object = get_taxonomy( $post->object );
if ( $object ) {
$post->type_label = $object->labels->singular_name;
@@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
-$wp_version = '4.7-alpha-38617';
+$wp_version = '4.7-alpha-38618';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 comments on commit 037a236

Please sign in to comment.