Index: wp-includes/theme.php
===================================================================
--- wp-includes/theme.php	(revision 26840)
+++ wp-includes/theme.php	(working copy)
@@ -1366,7 +1366,9 @@
  * The init hook may be too late for some features.
  *
  * @since 2.9.0
- * @param string $feature the feature being added
+ * @global array $_wp_theme_features All supported features.
+ * @param string $feature The feature being added.
+ * @return bool|void
  */
 function add_theme_support( $feature ) {
 	global $_wp_theme_features;
@@ -1560,29 +1562,45 @@
  * Gets the theme support arguments passed when registering that support
  *
  * @since 3.1
- * @param string $feature the feature to check
- * @return array The array of extra arguments
+ * @global array $_wp_theme_features All supported features.
+ * @param string $feature The feature to check.
+ * @return array|bool The array of extra arguments, or true if there are none.
  */
 function get_theme_support( $feature ) {
 	global $_wp_theme_features;
 	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 );
 }
 
 /**
@@ -1593,7 +1611,7 @@
  *
  * @since 3.0.0
  * @see add_theme_support()
- * @param string $feature the feature being added
+ * @param string $feature The feature being removed.
  * @return bool Whether feature was removed.
  */
 function remove_theme_support( $feature ) {
@@ -1609,28 +1627,26 @@
  *
  * @access private
  * @since 3.1.0
+ * @param string $feature The feature being removed.
+ * @return bool Whether feature was removed.
  */
 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 +1654,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;
 }
 
@@ -1653,16 +1668,14 @@
  * Checks a theme's support for a given feature
  *
  * @since 2.9.0
- * @param string $feature the feature being checked
- * @return boolean
+ * @param string $feature The feature being checked.
+ * @return boolean Whether the current theme supports the given feature.
  */
 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 +1689,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,15 +1703,15 @@
 			// 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':
 		case 'custom-background' :
 			// 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] );
+			$capability = $args[0];
+			return (bool) get_theme_support( $feature, $capability );
 			break;
 	}
 
@@ -1712,11 +1725,11 @@
 	 *
 	 * @since 3.4.0
 	 *
-	 * @param bool   true     Whether the current theme supports the given feature. Default true.
-	 * @param array  $args    Array of arguments for the feature.
-	 * @param string $feature The theme feature.
+	 * @param bool  true     Whether the current theme supports the given feature. Default true.
+	 * @param array $args    Array of arguments for the feature.
+	 * @param array $support Specific theme support for the 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 ) );
 }
 
 /**
