/** * Unregisters a navigation menu for a theme. * * @param array $location the menu location identifier * * @return bool True on success, false on failure. */ function unregister_nav_menu($location) { global $_wp_registered_nav_menus; 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; }
/** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which * runs before the init hook. The init hook is too late for some features, such * as indicating support for post thumbnails. */ public function afterSetupTheme() { /* * Load language for text domain from /lang dir */ load_theme_textdomain('DIRESS_DOMAIN', TEMPLATE_DIR . '/lang'); // Add default posts and comments RSS feed links to head. add_theme_support('automatic-feed-links'); /* * Let WordPress manage the document title. * By adding theme support, we declare that this theme does not use a * hard-coded <title> tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support('title-tag'); /* * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support('post-thumbnails'); _remove_theme_support('menus'); }
/** * Allows a theme to de-register its support of a certain feature * * Should be called in the theme's functions.php file. Generally would * be used for child themes to override support from the parent theme. * * @since 3.0.0 * @see add_theme_support() * @param string $feature the feature being added * @return bool Whether feature was removed. */ function remove_theme_support($feature) { // Blacklist: for internal registrations not used directly by themes. if (in_array($feature, array('editor-style', 'widgets', 'menus'))) { return false; } return _remove_theme_support($feature); }
/** * @ticket 26900 */ function test_supports_menus() { // Start fresh foreach (get_registered_nav_menus() as $location => $desc) { unregister_nav_menu($location); } _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')); }