From 7e923cc0fe9404a1b324d37a13047313abd007b7 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Thu, 8 Oct 2015 18:26:13 +0000 Subject: [PATCH] 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 --- src/wp-includes/post-template.php | 5 +++++ tests/phpunit/tests/post/template.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index 1c98e49ede..3b491a1ace 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -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 diff --git a/tests/phpunit/tests/post/template.php b/tests/phpunit/tests/post/template.php index 7fe86c047b..5c80082510 100644 --- a/tests/phpunit/tests/post/template.php +++ b/tests/phpunit/tests/post/template.php @@ -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 ''. $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( '/