From 1b026367932f3f631a344846966d382fa9b99d11 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 6 Jul 2015 05:52:59 +0000 Subject: [PATCH] Customizer: Ensure that a newly-added nav menu item gets the Original link populated in its control. Props valendesigns. Fixes #32858. git-svn-id: https://develop.svn.wordpress.org/trunk@33089 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-nav-menus.php | 12 ++++++++---- tests/phpunit/tests/customize/nav-menus.php | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/class-wp-customize-nav-menus.php b/src/wp-includes/class-wp-customize-nav-menus.php index 3d9e60f565..7d32cbb743 100644 --- a/src/wp-includes/class-wp-customize-nav-menus.php +++ b/src/wp-includes/class-wp-customize-nav-menus.php @@ -120,7 +120,8 @@ final class WP_Customize_Nav_Menus { 'type' => 'post_type', 'type_label' => get_post_type_object( $post->post_type )->labels->singular_name, 'object' => $post->post_type, - 'object_id' => (int) $post->ID, + 'object_id' => intval( $post->ID ), + 'url' => get_permalink( intval( $post->ID ) ), ); } } elseif ( 'taxonomy' === $obj_type ) { @@ -147,7 +148,8 @@ final class WP_Customize_Nav_Menus { 'type' => 'taxonomy', 'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name, 'object' => $term->taxonomy, - 'object_id' => $term->term_id, + 'object_id' => intval( $term->term_id ), + 'url' => get_term_link( intval( $term->term_id ), $term->taxonomy ), ); } } @@ -228,11 +230,12 @@ final class WP_Customize_Nav_Menus { } $results[] = array( 'id' => 'post-' . $post->ID, + 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), 'type' => 'post_type', 'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name, 'object' => $post->post_type, 'object_id' => intval( $post->ID ), - 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), + 'url' => get_permalink( intval( $post->ID ) ), ); } } @@ -250,11 +253,12 @@ final class WP_Customize_Nav_Menus { foreach ( $terms as $term ) { $results[] = array( 'id' => 'term-' . $term->term_id, + 'title' => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ), 'type' => 'taxonomy', 'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name, 'object' => $term->taxonomy, 'object_id' => intval( $term->term_id ), - 'title' => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ), + 'url' => get_term_link( intval( $term->term_id ), $term->taxonomy ), ); } } diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index 0cb6fe655e..7c0ee3d039 100644 --- a/tests/phpunit/tests/customize/nav-menus.php +++ b/tests/phpunit/tests/customize/nav-menus.php @@ -97,11 +97,12 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { foreach ( $post_ids as $post_id ) { $expected = array( 'id' => 'post-' . $post_id, + 'title' => html_entity_decode( get_the_title( $post_id ) ), 'type' => 'post_type', 'type_label' => get_post_type_object( 'post' )->labels->singular_name, 'object' => 'post', 'object_id' => intval( $post_id ), - 'title' => html_entity_decode( get_the_title( $post_id ) ), + 'url' => get_permalink( intval( $post_id ) ), ); wp_set_object_terms( $post_id, $term_ids, 'category' ); $search = $post_id === $post_ids[0] ? 'test & search' : 'other title'; @@ -115,11 +116,12 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { $term = get_term_by( 'id', $term_id, 'category' ); $expected = array( 'id' => 'term-' . $term_id, + 'title' => $term->name, 'type' => 'taxonomy', 'type_label' => get_taxonomy( 'category' )->labels->singular_name, 'object' => 'category', 'object_id' => intval( $term_id ), - 'title' => $term->name, + 'url' => get_term_link( intval( $term_id ), 'category' ), ); $s = sanitize_text_field( wp_unslash( $term->name ) ); $results = $menus->search_available_items_query( array( 'pagenum' => 1, 's' => $s ) );