WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/06/2016 09:05:45 AM (5 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/nav-menu-template.php

    r38470 r38523  
    4141 *     @type string             $items_wrap      How the list items should be wrapped. Default is a ul with an id and class.
    4242 *                                               Uses printf() format with numbered placeholders.
     43 *     @type string             $item_spacing    Whether whitespace format the menu's HTML: 'discard' or 'preserve' (default).
    4344 * }
    4445 * @return object|false|void Menu output if $echo is false, false if there are no items or no menu was found.
     
    4849
    4950    $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '',
    50     'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
     51    'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'item_spacing' => 'preserve',
    5152    'depth' => 0, 'walker' => '', 'theme_location' => '' );
    5253
    5354    $args = wp_parse_args( $args, $defaults );
     55
     56    if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
     57        // invalid value, fall back to default.
     58        $args['item_spacing'] = $defaults['item_spacing'];
     59    }
     60
    5461    /**
    5562     * Filters the arguments used to display a navigation menu.
Note: See TracChangeset for help on using the changeset viewer.