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. Built from https://develop.svn.wordpress.org/trunk@38523 git-svn-id: http://core.svn.wordpress.org/trunk@38464 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -53,8 +53,15 @@ class Walker_Page extends Walker {
|
||||
* Default empty array.
|
||||
*/
|
||||
public function start_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
$indent = str_repeat("\t", $depth);
|
||||
$output .= "\n$indent<ul class='children'>\n";
|
||||
if ( 'preserve' === $args['item_spacing'] ) {
|
||||
$t = "\t";
|
||||
$n = "\n";
|
||||
} else {
|
||||
$t = '';
|
||||
$n = '';
|
||||
}
|
||||
$indent = str_repeat( $t, $depth );
|
||||
$output .= "{$n}{$indent}<ul class='children'>{$n}";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,8 +78,15 @@ class Walker_Page extends Walker {
|
||||
* Default empty array.
|
||||
*/
|
||||
public function end_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
$indent = str_repeat("\t", $depth);
|
||||
$output .= "$indent</ul>\n";
|
||||
if ( 'preserve' === $args['item_spacing'] ) {
|
||||
$t = "\t";
|
||||
$n = "\n";
|
||||
} else {
|
||||
$t = '';
|
||||
$n = '';
|
||||
}
|
||||
$indent = str_repeat( $t, $depth );
|
||||
$output .= "{$indent}</ul>{$n}";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,8 +103,15 @@ class Walker_Page extends Walker {
|
||||
* @param int $current_page Optional. Page ID. Default 0.
|
||||
*/
|
||||
public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
|
||||
if ( 'preserve' === $args['item_spacing'] ) {
|
||||
$t = "\t";
|
||||
$n = "\n";
|
||||
} else {
|
||||
$t = '';
|
||||
$n = '';
|
||||
}
|
||||
if ( $depth ) {
|
||||
$indent = str_repeat( "\t", $depth );
|
||||
$indent = str_repeat( $t, $depth );
|
||||
} else {
|
||||
$indent = '';
|
||||
}
|
||||
@@ -175,7 +196,14 @@ class Walker_Page extends Walker {
|
||||
* @param array $args Optional. Array of arguments. Default empty array.
|
||||
*/
|
||||
public function end_el( &$output, $page, $depth = 0, $args = array() ) {
|
||||
$output .= "</li>\n";
|
||||
if ( 'preserve' === $args['item_spacing'] ) {
|
||||
$t = "\t";
|
||||
$n = "\n";
|
||||
} else {
|
||||
$t = '';
|
||||
$n = '';
|
||||
}
|
||||
$output .= "</li>{$n}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user