From d480f87831fab093a0d9a64ee2e64c65ed1cba2d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 30 Nov 2016 23:36:42 +0000 Subject: [PATCH] Customize: Fix handling of the nav menu item labels (titles) that match defaults (original titles) and fix the display of item type labels. * Show default labels for nav menu item as placeholders in a control's label field instead of showing blank. * Store empty string as label instead of copying default labels. * Prevent labels for post type archive items from being dropped in preview. * Also ensure that the item type label is displayed on nav menu item controls for settings that are loaded from an existing changeset. Amends [38618]. See #38015. Fixes #38955. Built from https://develop.svn.wordpress.org/trunk@39393 git-svn-id: http://core.svn.wordpress.org/trunk@39333 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- ...ass-wp-customize-nav-menu-item-setting.php | 69 +++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php b/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php index 802d67e9c4..11b5cd6d5a 100644 --- a/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php +++ b/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php @@ -233,6 +233,9 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { } else { $value = $post_value; } + if ( ! empty( $value ) && empty( $value['original_title'] ) ) { + $value['original_title'] = $this->get_original_title( (object) $value ); + } } elseif ( isset( $this->value ) ) { $value = $this->value; } else { @@ -260,6 +263,10 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { $value = $this->value; } + if ( ! empty( $value ) && empty( $value['type_label'] ) ) { + $value['type_label'] = $this->get_type_label( (object) $value ); + } + return $value; } @@ -273,11 +280,8 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { * @return string The original title. */ protected function get_original_title( $item ) { - if ( empty( $item->object_id ) ) { - return ''; - } $original_title = ''; - if ( 'post_type' === $item->type ) { + if ( 'post_type' === $item->type && ! empty( $item->object_id ) ) { $original_object = get_post( $item->object_id ); if ( $original_object ) { /** This filter is documented in wp-includes/post-template.php */ @@ -288,16 +292,53 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { $original_title = sprintf( __( '#%d (no title)' ), $original_object->ID ); } } - } elseif ( 'taxonomy' === $item->type ) { + } elseif ( 'taxonomy' === $item->type && ! empty( $item->object_id ) ) { $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; } + } elseif ( 'post_type_archive' === $item->type ) { + $original_object = get_post_type_object( $item->object ); + if ( $original_object ) { + $original_title = $original_object->labels->archives; + } } $original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) ); return $original_title; } + /** + * Get type label. + * + * @since 4.7.0 + * @access protected + * + * @param object $item Nav menu item. + * @returns string The type label. + */ + protected function get_type_label( $item ) { + if ( 'post_type' === $item->type ) { + $object = get_post_type_object( $item->object ); + if ( $object ) { + $type_label = $object->labels->singular_name; + } else { + $type_label = $item->object; + } + } elseif ( 'taxonomy' === $item->type ) { + $object = get_taxonomy( $item->object ); + if ( $object ) { + $type_label = $object->labels->singular_name; + } else { + $type_label = $item->object; + } + } elseif ( 'post_type_archive' === $item->type ) { + $type_label = __( 'Post Type Archive' ); + } else { + $type_label = __( 'Custom Link' ); + } + return $type_label; + } + /** * Ensure that the value is fully populated with the necessary properties. * @@ -584,23 +625,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { } if ( ! isset( $post->type_label ) ) { - if ( 'post_type' === $post->type ) { - $object = get_post_type_object( $post->object ); - if ( $object ) { - $post->type_label = $object->labels->singular_name; - } else { - $post->type_label = $post->object; - } - } elseif ( 'taxonomy' === $post->type ) { - $object = get_taxonomy( $post->object ); - if ( $object ) { - $post->type_label = $object->labels->singular_name; - } else { - $post->type_label = $post->object; - } - } else { - $post->type_label = __( 'Custom Link' ); - } + $post->type_label = $this->get_type_label( $post ); } // Ensure nav menu item URL is set according to linked object. diff --git a/wp-includes/version.php b/wp-includes/version.php index e0f554d80d..da75fbc46a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-39392'; +$wp_version = '4.8-alpha-39393'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.