Index: wp-includes/nav-menu-template.php
===================================================================
--- wp-includes/nav-menu-template.php	(revision 17165)
+++ wp-includes/nav-menu-template.php	(working copy)
@@ -322,49 +322,41 @@
 		$classes[] = 'menu-item-type-' . $menu_item->type;
 		$classes[] = 'menu-item-object-' . $menu_item->object;
 
-		// if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
-		if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) {
-			$active_parent_object_ids[] = (int) $menu_item->object_id;
-			$active_parent_item_ids[] = (int) $menu_item->db_id;
-			$active_object = $queried_object->post_type;
+		$menu_item->force_inactive = false;
+		$menu_item->force_active = false;
+		$menu_item = apply_filters( 'nav_menu_active', $menu_item );
 
-		// if the menu item corresponds to the currently-queried post or taxonomy object
-		} elseif (
-			$menu_item->object_id == $queried_object_id &&
-			(
-				( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) ||
-				( 'post_type' == $menu_item->type && $wp_query->is_singular ) ||
-				( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) )
-			)
-		) {
-			$classes[] = 'current-menu-item';
-			$menu_items[$key]->current = true;
-			$_anc_id = (int) $menu_item->db_id;
+		if( !$menu_item->force_inactive ) {
+			if ( $menu_item->force_active ) {
+				$classes[] = 'current-menu-item';
+				$menu_items[$key]->current = true;
+				$_anc_id = (int) $menu_item->db_id;
 
-			while(
-				( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
-				! in_array( $_anc_id, $active_ancestor_item_ids )
-			) {
-				$active_ancestor_item_ids[] = $_anc_id;
-			}
+				while(
+					( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
+					! in_array( $_anc_id, $active_ancestor_item_ids )
+				) {
+					$active_ancestor_item_ids[] = $_anc_id;
+				}
 
-			if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) {
-				// Back compat classes for pages to match wp_page_menu()
-				$classes[] = 'page_item';
-				$classes[] = 'page-item-' . $menu_item->object_id;
-				$classes[] = 'current_page_item';
-			}
-			$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
-			$active_parent_object_ids[] = (int) $menu_item->post_parent;
-			$active_object = $menu_item->object;
+				$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
+				$active_parent_object_ids[] = (int) $menu_item->post_parent;
+				$active_object = $menu_item->object;
+			// if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
+			} elseif ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) {
+				$active_parent_object_ids[] = (int) $menu_item->object_id;
+				$active_parent_item_ids[] = (int) $menu_item->db_id;
+				$active_object = $queried_object->post_type;
 
-		// if the menu item corresponds to the currently-requested URL
-		} elseif ( 'custom' == $menu_item->object ) {
-			$current_url = untrailingslashit( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
-			$item_url = untrailingslashit( strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url );
-			$_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) );
-
-			if ( in_array( $item_url, array( $current_url, $_indexless_current ) ) ) {
+			// if the menu item corresponds to the currently-queried post or taxonomy object
+			} elseif (
+				$menu_item->object_id == $queried_object_id &&
+				(
+					( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) ||
+					( 'post_type' == $menu_item->type && $wp_query->is_singular ) ||
+					( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) )
+				)
+			) {
 				$classes[] = 'current-menu-item';
 				$menu_items[$key]->current = true;
 				$_anc_id = (int) $menu_item->db_id;
@@ -376,27 +368,57 @@
 					$active_ancestor_item_ids[] = $_anc_id;
 				}
 
-				if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) {
-					// Back compat for home link to match wp_page_menu()
+				if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) {
+					// Back compat classes for pages to match wp_page_menu()
+					$classes[] = 'page_item';
+					$classes[] = 'page-item-' . $menu_item->object_id;
 					$classes[] = 'current_page_item';
 				}
 				$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
 				$active_parent_object_ids[] = (int) $menu_item->post_parent;
 				$active_object = $menu_item->object;
 
-			// give front page item current-menu-item class when extra query arguments involved
-			} elseif ( $item_url == $front_page_url && is_front_page() ) {
-				$classes[] = 'current-menu-item';
+			// if the menu item corresponds to the currently-requested URL
+			} elseif ( 'custom' == $menu_item->object ) {
+				$current_url = untrailingslashit( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
+				$item_url = untrailingslashit( strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url );
+				$_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) );
+
+				if ( in_array( $item_url, array( $current_url, $_indexless_current ) ) ) {
+					$classes[] = 'current-menu-item';
+					$menu_items[$key]->current = true;
+					$_anc_id = (int) $menu_item->db_id;
+
+					while(
+						( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
+						! in_array( $_anc_id, $active_ancestor_item_ids )
+					) {
+						$active_ancestor_item_ids[] = $_anc_id;
+					}
+
+					if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) {
+						// Back compat for home link to match wp_page_menu()
+						$classes[] = 'current_page_item';
+					}
+					$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
+					$active_parent_object_ids[] = (int) $menu_item->post_parent;
+					$active_object = $menu_item->object;
+
+				// give front page item current-menu-item class when extra query arguments involved
+				} elseif ( $item_url == $front_page_url && is_front_page() ) {
+					$classes[] = 'current-menu-item';
+				}
+
+				if ( untrailingslashit($item_url) == home_url() )
+					$classes[] = 'menu-item-home';
 			}
 
-			if ( untrailingslashit($item_url) == home_url() )
-				$classes[] = 'menu-item-home';
+			// back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
+			if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id )
+				$classes[] = 'current_page_parent';
 		}
-
-		// back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
-		if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id )
-			$classes[] = 'current_page_parent';
-
+		unset( $menu_item->force_inactive );
+		unset( $menu_item->force_active );
 		$menu_items[$key]->classes = array_unique( $classes );
 	}
 	$active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) );
@@ -426,7 +448,7 @@
 					'taxonomy' == $parent_item->type &&
 					isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) &&
 					in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) &&
-					(	
+					(
 						! isset( $queried_object->term_id ) ||
 						$parent_item->object_id != $queried_object->term_id
 					)
