Make WordPress Core


Ignore:
Timestamp:
09/06/2016 09:05:45 AM (9 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-page.php

    r37518 r38523  
    5454     */
    5555    public function start_lvl( &$output, $depth = 0, $args = array() ) {
    56         $indent = str_repeat("\t", $depth);
    57         $output .= "\n$indent<ul class='children'>\n";
     56        if ( 'preserve' === $args['item_spacing'] ) {
     57            $t = "\t";
     58            $n = "\n";
     59        } else {
     60            $t = '';
     61            $n = '';
     62        }
     63        $indent = str_repeat( $t, $depth );
     64        $output .= "{$n}{$indent}<ul class='children'>{$n}";
    5865    }
    5966
     
    7279     */
    7380    public function end_lvl( &$output, $depth = 0, $args = array() ) {
    74         $indent = str_repeat("\t", $depth);
    75         $output .= "$indent</ul>\n";
     81        if ( 'preserve' === $args['item_spacing'] ) {
     82            $t = "\t";
     83            $n = "\n";
     84        } else {
     85            $t = '';
     86            $n = '';
     87        }
     88        $indent = str_repeat( $t, $depth );
     89        $output .= "{$indent}</ul>{$n}";
    7690    }
    7791
     
    90104     */
    91105    public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
     106        if ( 'preserve' === $args['item_spacing'] ) {
     107            $t = "\t";
     108            $n = "\n";
     109        } else {
     110            $t = '';
     111            $n = '';
     112        }
    92113        if ( $depth ) {
    93             $indent = str_repeat( "\t", $depth );
     114            $indent = str_repeat( $t, $depth );
    94115        } else {
    95116            $indent = '';
     
    176197     */
    177198    public function end_el( &$output, $page, $depth = 0, $args = array() ) {
    178         $output .= "</li>\n";
     199        if ( 'preserve' === $args['item_spacing'] ) {
     200            $t = "\t";
     201            $n = "\n";
     202        } else {
     203            $t = '';
     204            $n = '';
     205        }
     206        $output .= "</li>{$n}";
    179207    }
    180208
Note: See TracChangeset for help on using the changeset viewer.