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.



git-svn-id: https://develop.svn.wordpress.org/trunk@34950 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Konstantin Obenland
2015-10-08 18:26:13 +00:00
parent ab296be565
commit 7e923cc0fe
2 changed files with 15 additions and 0 deletions

View File

@@ -1275,6 +1275,11 @@ function wp_page_menu( $args = array() ) {
$container = sanitize_text_field( $args['container'] );
// Fallback in case `wp_nav_menu()` was called without a container.
if ( empty( $container ) ) {
$container = 'div';
}
if ( $menu ) {
// wp_nav_menu doesn't set before and after

View File

@@ -281,6 +281,7 @@ NO;
/**
* @ticket 11095
* @ticket 33974
*/
public function test_wp_page_menu_wp_nav_menu_fallback() {
$pages = $this->factory->post->create_many( 3, array( 'post_type' => 'page' ) );
@@ -293,5 +294,14 @@ NO;
// After falling back, the 'after' argument should be set and output as '</ul>'.
$this->assertRegExp( '/<\/ul><\/div>/', $menu );
// No menus + wp_nav_menu() falls back to wp_page_menu(), this time without a container.
$menu = wp_nav_menu( array(
'echo' => false,
'container' => false,
) );
// After falling back, the empty 'container' argument should still return a container element.
$this->assertRegExp( '/<div class="menu">/', $menu );
}
}