Nav Menus: In `Walker_Nav_Menu_Edit::start_el()` initialize `$original_title` with `false`.

Prevents displaying "Original:" without a title when adding a menu item without a title.

Props grapplerulrich, swissspidy.
Fixes #36729.

git-svn-id: https://develop.svn.wordpress.org/trunk@37953 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling 2016-07-04 20:15:48 +00:00
parent f7c680e84f
commit 2f90caa574
2 changed files with 61 additions and 1 deletions

View File

@ -70,7 +70,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
'_wpnonce',
);
$original_title = '';
$original_title = false;
if ( 'taxonomy' == $item->type ) {
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
if ( is_wp_error( $original_title ) )

View File

@ -0,0 +1,60 @@
<?php
/**
* @group navmenus
* @group walker
*/
class Tests_Walker_Nav_Menu_Edit extends WP_UnitTestCase {
protected $_wp_nav_menu_max_depth;
function setUp() {
global $_wp_nav_menu_max_depth;
parent::setUp();
/** Walker_Nav_Menu_Edit class */
require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php' );
$this->walker = new Walker_Nav_Menu_Edit();
$this->_wp_nav_menu_max_depth = $_wp_nav_menu_max_depth;
}
function tearDown() {
global $_wp_nav_menu_max_depth;
$_wp_nav_menu_max_depth = $this->_wp_nav_menu_max_depth;
parent::tearDown();
}
/**
* @ticket 36729
*/
function test_original_title_prefix_should_not_be_shown_if_empty() {
$expected = '';
$post_id = $this->factory->post->create();
$item = array(
'classes' => array(),
'description' => '',
'ID' => $post_id,
'menu_item_parent' => 0,
'menu_order' => 0,
'object_id' => $post_id,
'object' => 'post',
'post_excerpt' => get_the_excerpt( $post_id ),
'title' => get_the_title( $post_id ),
'type' => 'foobar',
'type_label' => 'Foo Bar',
'target' => '_blank',
'url' => '',
'xfn' => '',
);
$this->walker->start_el( $expected, (object) $item );
$this->assertNotRegExp( '#<p class="link-to-original">\s*Original: <a href=""></a>#', $expected );
}
}