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
This commit is contained in:
Andrew Nacin 2014-02-21 18:13:52 +00:00
parent 4cfcdabdd8
commit b74f222d33
2 changed files with 30 additions and 0 deletions

View File

@ -90,6 +90,9 @@ function unregister_nav_menu( $location ) {
if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[$location] ) ) { if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[$location] ) ) {
unset( $_wp_registered_nav_menus[$location] ); unset( $_wp_registered_nav_menus[$location] );
if ( empty( $_wp_registered_nav_menus ) ) {
_remove_theme_support( 'menus' );
}
return true; return true;
} }
return false; return false;

View File

@ -156,4 +156,31 @@ class Tests_Theme_Support extends WP_UnitTestCase {
remove_theme_support( 'foobar' ); remove_theme_support( 'foobar' );
$this->assertFalse( current_theme_supports( 'foobar', 'bar' ) ); $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' ) );
}
} }