mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user