WordPress.org

Make WordPress Core

Changeset 34950


Ignore:
Timestamp:
10/08/2015 06:26:13 PM (5 years ago)
Author:
obenland
Message:

Template: Add fallback for empty containers.

Since [14031] the container can be omitted in wp_nav_menu(). It can not
however in wp_page_menu(), which creates a conflict if it is set as
the fallback, Let's make sure there is always a valid container tag.

Fixes #33974.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-template.php

    r34881 r34950  
    12761276    $container = sanitize_text_field( $args['container'] );
    12771277
     1278    // Fallback in case `wp_nav_menu()` was called without a container.
     1279    if ( empty( $container ) ) {
     1280        $container = 'div';
     1281    }
     1282
    12781283    if ( $menu ) {
    12791284
  • trunk/tests/phpunit/tests/post/template.php

    r34654 r34950  
    282282    /**
    283283     * @ticket 11095
     284     * @ticket 33974
    284285     */
    285286    public function test_wp_page_menu_wp_nav_menu_fallback() {
     
    294295        // After falling back, the 'after' argument should be set and output as '</ul>'.
    295296        $this->assertRegExp( '/<\/ul><\/div>/', $menu );
     297
     298        // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without a container.
     299        $menu = wp_nav_menu( array(
     300            'echo'      => false,
     301            'container' => false,
     302        ) );
     303
     304        // After falling back, the empty 'container' argument should still return a container element.
     305        $this->assertRegExp( '/<div class="menu">/', $menu );
    296306    }
    297307}
Note: See TracChangeset for help on using the changeset viewer.