Make WordPress Core


Ignore:
Timestamp:
09/06/2016 09:05:45 AM (8 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-walker-nav-menu.php

    r37640 r38523  
    5151     */
    5252    public function start_lvl( &$output, $depth = 0, $args = array() ) {
    53         $indent = str_repeat("\t", $depth);
    54         $output .= "\n$indent<ul class=\"sub-menu\">\n";
     53        if ( 'preserve' === $args->item_spacing ) {
     54            $t = "\t";
     55            $n = "\n";
     56        } else {
     57            $t = '';
     58            $n = '';
     59        }
     60        $indent = str_repeat( $t, $depth );
     61        $output .= "{$n}{$indent}<ul class=\"sub-menu\">{$n}";
    5562    }
    5663
     
    6774     */
    6875    public function end_lvl( &$output, $depth = 0, $args = array() ) {
    69         $indent = str_repeat("\t", $depth);
    70         $output .= "$indent</ul>\n";
     76        if ( 'preserve' === $args->item_spacing ) {
     77            $t = "\t";
     78            $n = "\n";
     79        } else {
     80            $t = '';
     81            $n = '';
     82        }
     83        $indent = str_repeat( $t, $depth );
     84        $output .= "$indent</ul>{$n}";
    7185    }
    7286
     
    86100     */
    87101    public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
    88         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
     102        if ( 'preserve' === $args->item_spacing ) {
     103            $t = "\t";
     104            $n = "\n";
     105        } else {
     106            $t = '';
     107            $n = '';
     108        }
     109        $indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
    89110
    90111        $classes = empty( $item->classes ) ? array() : (array) $item->classes;
     
    217238     */
    218239    public function end_el( &$output, $item, $depth = 0, $args = array() ) {
    219         $output .= "</li>\n";
     240        if ( 'preserve' === $args->item_spacing ) {
     241            $t = "\t";
     242            $n = "\n";
     243        } else {
     244            $t = '';
     245            $n = '';
     246        }
     247        $output .= "</li>{$n}";
    220248    }
    221249
Note: See TracChangeset for help on using the changeset viewer.