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
This commit is contained in:
Weston Ruter 2015-07-06 05:52:59 +00:00
parent 0f7208a1ee
commit 1b02636793
2 changed files with 12 additions and 6 deletions

View File

@ -120,7 +120,8 @@ final class WP_Customize_Nav_Menus {
'type' => 'post_type', 'type' => 'post_type',
'type_label' => get_post_type_object( $post->post_type )->labels->singular_name, 'type_label' => get_post_type_object( $post->post_type )->labels->singular_name,
'object' => $post->post_type, 'object' => $post->post_type,
'object_id' => (int) $post->ID, 'object_id' => intval( $post->ID ),
'url' => get_permalink( intval( $post->ID ) ),
); );
} }
} elseif ( 'taxonomy' === $obj_type ) { } elseif ( 'taxonomy' === $obj_type ) {
@ -147,7 +148,8 @@ final class WP_Customize_Nav_Menus {
'type' => 'taxonomy', 'type' => 'taxonomy',
'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name, 'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name,
'object' => $term->taxonomy, '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( $results[] = array(
'id' => 'post-' . $post->ID, 'id' => 'post-' . $post->ID,
'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),
'type' => 'post_type', 'type' => 'post_type',
'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name, 'type_label' => $post_type_objects[ $post->post_type ]->labels->singular_name,
'object' => $post->post_type, 'object' => $post->post_type,
'object_id' => intval( $post->ID ), '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 ) { foreach ( $terms as $term ) {
$results[] = array( $results[] = array(
'id' => 'term-' . $term->term_id, 'id' => 'term-' . $term->term_id,
'title' => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ),
'type' => 'taxonomy', 'type' => 'taxonomy',
'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name, 'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name,
'object' => $term->taxonomy, 'object' => $term->taxonomy,
'object_id' => intval( $term->term_id ), '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 ),
); );
} }
} }

View File

@ -97,11 +97,12 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase {
foreach ( $post_ids as $post_id ) { foreach ( $post_ids as $post_id ) {
$expected = array( $expected = array(
'id' => 'post-' . $post_id, 'id' => 'post-' . $post_id,
'title' => html_entity_decode( get_the_title( $post_id ) ),
'type' => 'post_type', 'type' => 'post_type',
'type_label' => get_post_type_object( 'post' )->labels->singular_name, 'type_label' => get_post_type_object( 'post' )->labels->singular_name,
'object' => 'post', 'object' => 'post',
'object_id' => intval( $post_id ), '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' ); wp_set_object_terms( $post_id, $term_ids, 'category' );
$search = $post_id === $post_ids[0] ? 'test & search' : 'other title'; $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' ); $term = get_term_by( 'id', $term_id, 'category' );
$expected = array( $expected = array(
'id' => 'term-' . $term_id, 'id' => 'term-' . $term_id,
'title' => $term->name,
'type' => 'taxonomy', 'type' => 'taxonomy',
'type_label' => get_taxonomy( 'category' )->labels->singular_name, 'type_label' => get_taxonomy( 'category' )->labels->singular_name,
'object' => 'category', 'object' => 'category',
'object_id' => intval( $term_id ), 'object_id' => intval( $term_id ),
'title' => $term->name, 'url' => get_term_link( intval( $term_id ), 'category' ),
); );
$s = sanitize_text_field( wp_unslash( $term->name ) ); $s = sanitize_text_field( wp_unslash( $term->name ) );
$results = $menus->search_available_items_query( array( 'pagenum' => 1, 's' => $s ) ); $results = $menus->search_available_items_query( array( 'pagenum' => 1, 's' => $s ) );