Index: wp-includes/theme.php
===================================================================
--- wp-includes/theme.php	(revision 26840)
+++ wp-includes/theme.php	(working copy)
@@ -1568,21 +1568,36 @@
 	if ( ! isset( $_wp_theme_features[ $feature ] ) )
 		return false;
 
-	if ( func_num_args() <= 1 )
-		return $_wp_theme_features[ $feature ];
-
 	$args = array_slice( func_get_args(), 1 );
-	switch ( $feature ) {
-		case 'custom-header' :
-		case 'custom-background' :
-			if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) )
-				return $_wp_theme_features[ $feature ][0][ $args[0] ];
-			return false;
-			break;
-		default :
-			return $_wp_theme_features[ $feature ];
-			break;
+	if ( ! empty( $args ) ) {
+		switch ( $feature ) {
+			case 'custom-header' :
+			case 'custom-background' :
+				if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) )
+					return $_wp_theme_features[ $feature ][0][ $args[0] ];
+				return false;
+				break;
+		}
+	}
+
+	$feature_args = $_wp_theme_features[ $feature ];
+	if ( is_array( $feature_args ) ) {
+		$feature_args = array_merge( $feature_args, $_wp_theme_features[ $feature ][0] );
 	}
+
+	/**
+	 * Filter whether the theme support for a specific feature.
+	 *
+	 * The dynamic portion of the hook name, $feature, refers to
+	 * the specific theme feature. Possible values include 'post-formats',
+	 * 'post-thumbnails', 'menus', 'automatic-feed-links', and 'html5'.
+	 *
+	 * @since 3.9.0
+	 *
+	 * @param array|bool $feature_args The array of extra arguments, or true if there are none.
+	 * @param array      $args         Array of arguments for the feature.
+	 */
+	return apply_filters( "get_theme_support-{$feature}", $feature_args, $args );
 }
 
 /**
@@ -1611,26 +1626,22 @@
  * @since 3.1.0
  */
 function _remove_theme_support( $feature ) {
-	global $_wp_theme_features;
-
 	switch ( $feature ) {
 		case 'custom-header-uploads' :
-			if ( ! isset( $_wp_theme_features['custom-header'] ) )
+			if ( ! current_theme_supports( 'custom-header' ) )
 				return false;
 			add_theme_support( 'custom-header', array( 'uploads' => false ) );
 			return; // Do not continue - custom-header-uploads no longer exists.
 	}
 
-	if ( ! isset( $_wp_theme_features[ $feature ] ) )
+	if ( ! current_theme_supports( $feature ) )
 		return false;
 
 	switch ( $feature ) {
 		case 'custom-header' :
 			if ( ! did_action( 'wp_loaded' ) )
 				break;
-			$support = get_theme_support( 'custom-header' );
-			if ( $support[0]['wp-head-callback'] )
-				remove_action( 'wp_head', $support[0]['wp-head-callback'] );
+			remove_action( 'wp_head', get_theme_support( 'custom-header', 'wp-head-callback' ) );
 			remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) );
 			unset( $GLOBALS['custom_image_header'] );
 			break;
@@ -1638,14 +1649,13 @@
 		case 'custom-background' :
 			if ( ! did_action( 'wp_loaded' ) )
 				break;
-			$support = get_theme_support( 'custom-background' );
-			remove_action( 'wp_head', $support[0]['wp-head-callback'] );
+			remove_action( 'wp_head', get_theme_support( 'custom-background', 'wp-head-callback' ) );
 			remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) );
 			unset( $GLOBALS['custom_background'] );
 			break;
 	}
 
-	unset( $_wp_theme_features[ $feature ] );
+	unset( $GLOBALS['_wp_theme_features'][ $feature ] );
 	return true;
 }
 
@@ -1657,12 +1667,10 @@
  * @return boolean
  */
 function current_theme_supports( $feature ) {
-	global $_wp_theme_features;
-
 	if ( 'custom-header-uploads' == $feature )
 		return current_theme_supports( 'custom-header', 'uploads' );
 
-	if ( !isset( $_wp_theme_features[$feature] ) )
+	if ( ! get_theme_support( $feature ) )
 		return false;
 
 	// If no args passed then no extra checks need be performed
@@ -1676,10 +1684,10 @@
 			// post-thumbnails can be registered for only certain content/post types by passing
 			// an array of types to add_theme_support(). If no array was passed, then
 			// any type is accepted
-			if ( true === $_wp_theme_features[$feature] )  // Registered for all types
+			if ( true === get_theme_support( $feature ) )  // Registered for all types
 				return true;
 			$content_type = $args[0];
-			return in_array( $content_type, $_wp_theme_features[$feature][0] );
+			return in_array( $content_type, get_theme_support( $feature ) );
 			break;
 
 		case 'html5':
@@ -1690,7 +1698,7 @@
 			// Specific areas of HTML5 support *must* be passed via an array to add_theme_support()
 
 			$type = $args[0];
-			return in_array( $type, $_wp_theme_features[$feature][0] );
+			return in_array( $type, get_theme_support( $feature ) );
 			break;
 
 		case 'custom-header':
@@ -1698,7 +1706,7 @@
 			// specific custom header and background capabilities can be registered by passing
 			// an array to add_theme_support()
 			$header_support = $args[0];
-			return ( isset( $_wp_theme_features[$feature][0][$header_support] ) && $_wp_theme_features[$feature][0][$header_support] );
+			return get_theme_support( $feature, $header_support );
 			break;
 	}
 
@@ -1716,7 +1724,7 @@
 	 * @param array  $args    Array of arguments for the feature.
 	 * @param string $feature The theme feature.
 	 */
-	return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[$feature] );
+	return apply_filters( "current_theme_supports-{$feature}", true, $args, get_theme_support( $feature ) );
 }
 
 /**
