mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-10 21:00:59 +01:00
Customize: Ensure nav menu items lacking a label use the title from the 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
This commit is contained in:
parent
ea69657b59
commit
037a236e42
@ -1397,14 +1397,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var titleEl = control.container.find( '.menu-item-title' ),
|
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 ) {
|
if ( item._invalid ) {
|
||||||
titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText );
|
titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't update to an empty title.
|
// Don't update to an empty title.
|
||||||
if ( item.title ) {
|
if ( item.title || item.original_title ) {
|
||||||
titleEl
|
titleEl
|
||||||
.text( titleText )
|
.text( titleText )
|
||||||
.removeClass( 'no-title' );
|
.removeClass( 'no-title' );
|
||||||
|
4
wp-admin/js/customize-nav-menus.min.js
vendored
4
wp-admin/js/customize-nav-menus.min.js
vendored
File diff suppressed because one or more lines are too long
@ -587,6 +587,10 @@ final class WP_Customize_Nav_Menus {
|
|||||||
$menu_item_setting_id = 'nav_menu_item[' . $item->ID . ']';
|
$menu_item_setting_id = 'nav_menu_item[' . $item->ID . ']';
|
||||||
|
|
||||||
$value = (array) $item;
|
$value = (array) $item;
|
||||||
|
if ( empty( $value['post_title'] ) ) {
|
||||||
|
$value['title'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
$value['nav_menu_term_id'] = $menu_id;
|
$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(
|
$this->manager->add_setting( new WP_Customize_Nav_Menu_Item_Setting( $this->manager, $menu_item_setting_id, array(
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
|
@ -69,7 +69,7 @@ class WP_Customize_Nav_Menu_Item_Control extends WP_Customize_Control {
|
|||||||
<span class="item-type" aria-hidden="true">{{ data.item_type_label }}</span>
|
<span class="item-type" aria-hidden="true">{{ data.item_type_label }}</span>
|
||||||
<span class="item-title" aria-hidden="true">
|
<span class="item-title" aria-hidden="true">
|
||||||
<span class="spinner"></span>
|
<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>
|
||||||
<span class="item-controls">
|
<span class="item-controls">
|
||||||
<button type="button" class="button-link item-edit" aria-expanded="false"><span class="screen-reader-text"><?php
|
<button type="button" class="button-link item-edit" aria-expanded="false"><span class="screen-reader-text"><?php
|
||||||
@ -96,7 +96,7 @@ class WP_Customize_Nav_Menu_Item_Control extends WP_Customize_Control {
|
|||||||
<p class="description description-thin">
|
<p class="description description-thin">
|
||||||
<label for="edit-menu-item-title-{{ data.menu_item_id }}">
|
<label for="edit-menu-item-title-{{ data.menu_item_id }}">
|
||||||
<?php _e( 'Navigation Label' ); ?><br />
|
<?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>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<p class="field-link-target description description-thin">
|
<p class="field-link-target description description-thin">
|
||||||
|
@ -233,7 +233,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
|||||||
} else {
|
} else {
|
||||||
$value = $post_value;
|
$value = $post_value;
|
||||||
}
|
}
|
||||||
} else if ( isset( $this->value ) ) {
|
} elseif ( isset( $this->value ) ) {
|
||||||
$value = $this->value;
|
$value = $this->value;
|
||||||
} else {
|
} else {
|
||||||
$value = false;
|
$value = false;
|
||||||
@ -242,7 +242,11 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
|||||||
if ( $this->post_id > 0 ) {
|
if ( $this->post_id > 0 ) {
|
||||||
$post = get_post( $this->post_id );
|
$post = get_post( $this->post_id );
|
||||||
if ( $post && self::POST_TYPE === $post->post_type ) {
|
if ( $post && self::POST_TYPE === $post->post_type ) {
|
||||||
|
$is_title_empty = empty( $post->post_title );
|
||||||
$value = (array) wp_setup_nav_menu_item( $post );
|
$value = (array) wp_setup_nav_menu_item( $post );
|
||||||
|
if ( $is_title_empty ) {
|
||||||
|
$value['title'] = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,6 +263,40 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
|||||||
return $value;
|
return $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.
|
* Ensure that the value is fully populated with the necessary properties.
|
||||||
*
|
*
|
||||||
@ -284,16 +322,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $this->value['original_title'] ) ) {
|
if ( ! isset( $this->value['original_title'] ) ) {
|
||||||
$original_title = '';
|
$this->value['original_title'] = $this->get_original_title( (object) $this->value );
|
||||||
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' ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $this->value['nav_menu_term_id'] ) && $this->post_id > 0 ) {
|
if ( ! isset( $this->value['nav_menu_term_id'] ) && $this->post_id > 0 ) {
|
||||||
@ -534,6 +563,12 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
|||||||
$item->menu_order = $item->position;
|
$item->menu_order = $item->position;
|
||||||
unset( $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 ) {
|
if ( $item->title ) {
|
||||||
$item->post_title = $item->title;
|
$item->post_title = $item->title;
|
||||||
}
|
}
|
||||||
@ -554,7 +589,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
|||||||
} else {
|
} else {
|
||||||
$post->type_label = $post->object;
|
$post->type_label = $post->object;
|
||||||
}
|
}
|
||||||
} elseif ( 'taxonomy' == $post->type ) {
|
} elseif ( 'taxonomy' === $post->type ) {
|
||||||
$object = get_taxonomy( $post->object );
|
$object = get_taxonomy( $post->object );
|
||||||
if ( $object ) {
|
if ( $object ) {
|
||||||
$post->type_label = $object->labels->singular_name;
|
$post->type_label = $object->labels->singular_name;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user