From b74f222d331d7caf35fdcf15a73287d02ef754fd Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Fri, 21 Feb 2014 18:13:52 +0000 Subject: [PATCH] Remove theme support for 'menus' in unregister_nav_menu() when there are no more menus. props kovshenin. fixes #26900. git-svn-id: https://develop.svn.wordpress.org/trunk@27220 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/nav-menu.php | 3 +++ tests/phpunit/tests/theme/support.php | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index af69dfc897..1672b03b8a 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -90,6 +90,9 @@ function unregister_nav_menu( $location ) { if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[$location] ) ) { unset( $_wp_registered_nav_menus[$location] ); + if ( empty( $_wp_registered_nav_menus ) ) { + _remove_theme_support( 'menus' ); + } return true; } return false; diff --git a/tests/phpunit/tests/theme/support.php b/tests/phpunit/tests/theme/support.php index 4c64a9db60..c0e71c139d 100644 --- a/tests/phpunit/tests/theme/support.php +++ b/tests/phpunit/tests/theme/support.php @@ -156,4 +156,31 @@ class Tests_Theme_Support extends WP_UnitTestCase { remove_theme_support( 'foobar' ); $this->assertFalse( current_theme_supports( 'foobar', 'bar' ) ); } + + /** + * @ticket 26900 + */ + function test_supports_menus() { + // Start fresh + _remove_theme_support( 'menus' ); + $this->assertFalse( current_theme_supports( 'menus' ) ); + + // Registering a nav menu automatically adds support. + register_nav_menu( 'primary', 'Primary Navigation' ); + register_nav_menu( 'secondary', 'Secondary Navigation' ); + $this->assertTrue( current_theme_supports( 'menus' ) ); + + // Support added internally, can't be removed. + remove_theme_support( 'menus' ); + $this->assertTrue( current_theme_supports( 'menus' ) ); + + // Still supports because of secondary. + unregister_nav_menu( 'primary' ); + $this->assertTrue( current_theme_supports( 'menus' ) ); + + // No longer support because we have no menus. + unregister_nav_menu( 'secondary' ); + $this->assertEmpty( get_registered_nav_menus() ); + $this->assertFalse( current_theme_supports( 'menus' ) ); + } }