WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/06/2016 09:05:45 AM (3 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/tests/phpunit/tests/post/template.php

    r35242 r38523  
    300300        $this->assertRegExp( '/<\/ul><\/div>/', $menu );
    301301
     302        // After falling back, the markup should include whitespace around <li>s
     303        $this->assertRegExp( '/\s<li.*>|<\/li>\s/U', $menu );
     304        $this->assertNotRegExp( '/><li.*>|<\/li></U', $menu );
     305
    302306        // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without a container.
    303307        $menu = wp_nav_menu( array(
     
    308312        // After falling back, the empty 'container' argument should still return a container element.
    309313        $this->assertRegExp( '/<div class="menu">/', $menu );
     314
     315        // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without white-space.
     316        $menu = wp_nav_menu( array(
     317            'echo'         => false,
     318            'item_spacing' => 'discard',
     319        ) );
     320
     321        // After falling back, the markup should not include whitespace around <li>s
     322        $this->assertNotRegExp( '/\s<li.*>|<\/li>\s/U', $menu );
     323        $this->assertRegExp( '/><li.*>|<\/li></U', $menu );
     324
    310325    }
    311326}
Note: See TracChangeset for help on using the changeset viewer.