Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revision 38260)
+++ src/wp-includes/post.php	(working copy)
@@ -3259,16 +3259,6 @@
 		}
 	}
 
-	// Set or remove featured image.
-	if ( isset( $postarr['_thumbnail_id'] ) && ( post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type ) ) {
-		$thumbnail_id = intval( $postarr['_thumbnail_id'] );
-		if ( -1 === $thumbnail_id ) {
-			delete_post_thumbnail( $post_ID );
-		} else {
-			set_post_thumbnail( $post_ID, $thumbnail_id );
-		}
-	}
-
 	if ( ! empty( $postarr['meta_input'] ) ) {
 		foreach ( $postarr['meta_input'] as $field => $value ) {
 			update_post_meta( $post_ID, $field, $value );
@@ -3292,6 +3282,27 @@
 		}
 	}
 
+	// Set or remove featured image.
+	if ( isset( $postarr['_thumbnail_id'] ) ) {
+		$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;
+		if ( ! $thumbnail_support && 'attachment' === $post_type && $post_mime_type ) {
+			if ( wp_attachment_is( 'audio', $post_ID ) ) {
+				$thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
+			} elseif ( wp_attachment_is( 'video', $post_ID ) ) {
+				$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
+			}
+		}
+
+		if ( $thumbnail_support ) {
+			$thumbnail_id = intval( $postarr['_thumbnail_id'] );
+			if ( -1 === $thumbnail_id ) {
+				delete_post_thumbnail( $post_ID );
+			} else {
+				set_post_thumbnail( $post_ID, $thumbnail_id );
+			}
+		}
+	}
+
 	clean_post_cache( $post_ID );
 
 	$post = get_post( $post_ID );
Index: tests/phpunit/tests/post/thumbnails.php
===================================================================
--- tests/phpunit/tests/post/thumbnails.php	(revision 38260)
+++ tests/phpunit/tests/post/thumbnails.php	(working copy)
@@ -233,4 +233,86 @@
 
 		$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
 	}
+
+	/**
+	 * @ticket 12922
+	 */
+	function test__wp_preview_post_thumbnail_filter() {
+		$old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
+
+		$GLOBALS['post'] = self::$post;
+		$_REQUEST['_thumbnail_id'] = self::$attachment_id;
+
+		$result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' );
+		$this->assertEquals( self::$attachment_id, $result );
+
+		unset( $_REQUEST['_thumbnail_id'] );
+		if ( null === $old_post ) {
+			unset( $GLOBALS['post'] );
+		} else {
+			$GLOBALS['post'] = $old_post;
+		}
+	}
+
+	/**
+	 * @ticket 12922
+	 */
+	function test_insert_post_with_post_thumbnail() {
+		$post_id = wp_insert_post( array(
+			'ID' => self::$post->ID,
+			'post_status' => 'publish',
+			'post_content' => rand_str(),
+			'post_title' => rand_str(),
+			'_thumbnail_id' => self::$attachment_id,
+		) );
+
+		$thumbnail_id = get_post_thumbnail_id( $post_id );
+		$this->assertEquals( self::$attachment_id, $thumbnail_id );
+
+		$post_id = wp_insert_post( array(
+			'ID' => $post_id,
+			'post_status' => 'publish',
+			'post_content' => rand_str(),
+			'post_title' => rand_str(),
+			'_thumbnail_id' => -1, // -1 removes post thumbnail.
+		) );
+
+		$thumbnail_id = get_post_thumbnail_id( $post_id );
+		$this->assertEmpty( $thumbnail_id );
+	}
+
+	/**
+	 * @ticket 37658
+	 */
+	function test_insert_attachment_with_post_thumbnail() {
+		// Audio files support featured images.
+		$post_id = wp_insert_post( array(
+			'post_type' => 'attachment',
+			'post_status' => 'inherit',
+			'post_content' => rand_str(),
+			'post_title' => rand_str(),
+			'post_mime_type' => 'audio/mpeg',
+			'post_parent' => 0,
+			'file' => DIR_TESTDATA . '/audio/test-noise.mp3', // File does not exist, but does not matter here.
+			'_thumbnail_id' => self::$attachment_id,
+		) );
+
+		$thumbnail_id = get_post_thumbnail_id( $post_id );
+		$this->assertEquals( self::$attachment_id, $thumbnail_id );
+
+		// Images do not support featured images.
+		$post_id = wp_insert_post( array(
+			'post_type' => 'attachment',
+			'post_status' => 'inherit',
+			'post_content' => rand_str(),
+			'post_title' => rand_str(),
+			'post_mime_type' => 'image/jpeg',
+			'post_parent' => 0,
+			'file' => DIR_TESTDATA . '/images/canola.jpg',
+			'_thumbnail_id' => self::$attachment_id,
+		) );
+
+		$thumbnail_id = get_post_thumbnail_id( $post_id );
+		$this->assertEmpty( $thumbnail_id );
+	}
 }
