Menus: Add white space option to wp_nav_menu() and wp_list_pages().

Adds an `item_spacing` option to the arguments array for the functions `wp_nav_menu()`, `wp_list_pages()`, and `wp_page_menu()`. `item_spacing` is a boolean accepting either `preserve` or `discard`.

Previously, certain CSS choices could result in a site's layout changing if `wp_nav_menu()` fell back to the default `wp_list_pages()` due to differences in the whitespace within the HTML. The new argument ensures a function outputs consistant HTML while maintaining backward compatibility.

Fixes #35206.


git-svn-id: https://develop.svn.wordpress.org/trunk@38523 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2016-09-06 09:05:45 +00:00
parent 18654d2778
commit 0c88ec217d
7 changed files with 213 additions and 41 deletions

View File

@@ -17,6 +17,7 @@ class Tests_List_Pages extends WP_UnitTestCase {
'link_before' => '',
'link_after' => '',
'walker' => '',
'item_spacing' => 'preserve',
'include' => '',
'post_type' => 'page',
'post_status' => 'publish',
@@ -342,4 +343,14 @@ class Tests_List_Pages extends WP_UnitTestCase {
$actual = wp_list_pages( $args );
$this->AssertEquals( $expected['exclude'], $actual );
}
function test_wp_list_pages_discarded_whitespace() {
$args = array(
'echo' => false,
'item_spacing' => 'discard',
);
$expected['default'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a><ul class=\'children\'><li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li><li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a></li><li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a></li></ul></li><li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a><ul class=\'children\'><li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a></li><li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a></li><li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li></ul></li><li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a><ul class=\'children\'><li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a></li><li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a></li><li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a></li></ul></li></ul></li>';
$actual = wp_list_pages( $args );
$this->AssertEquals( $expected['default'], $actual );
}
}