diff --git src/wp-includes/media.php src/wp-includes/media.php
index ace9021fd7..38f69b0c41 100644
--- src/wp-includes/media.php
+++ src/wp-includes/media.php
@@ -66,7 +66,7 @@ function image_constrain_size_for_editor( $width, $height, $size = 'medium', $co
 	if ( is_array( $size ) ) {
 		$max_width  = $size[0];
 		$max_height = $size[1];
-	} elseif ( $size == 'thumb' || $size == 'thumbnail' ) {
+	} elseif ( 'thumb' == $size || 'thumbnail' == $size ) {
 		$max_width  = intval( get_option( 'thumbnail_size_w' ) );
 		$max_height = intval( get_option( 'thumbnail_size_h' ) );
 		// last chance thumbnail size defaults
@@ -74,18 +74,18 @@ function image_constrain_size_for_editor( $width, $height, $size = 'medium', $co
 			$max_width  = 128;
 			$max_height = 96;
 		}
-	} elseif ( $size == 'medium' ) {
+	} elseif ( 'medium' == $size ) {
 		$max_width  = intval( get_option( 'medium_size_w' ) );
 		$max_height = intval( get_option( 'medium_size_h' ) );
 
-	} elseif ( $size == 'medium_large' ) {
+	} elseif ( 'medium_large' == $size ) {
 		$max_width  = intval( get_option( 'medium_large_size_w' ) );
 		$max_height = intval( get_option( 'medium_large_size_h' ) );
 
 		if ( intval( $content_width ) > 0 ) {
 			$max_width = min( intval( $content_width ), $max_width );
 		}
-	} elseif ( $size == 'large' ) {
+	} elseif ( 'large' == $size ) {
 		/*
 		 * We're inserting a large size image into the editor. If it's a really
 		 * big image we'll scale it down to fit reasonably within the editor
@@ -195,15 +195,20 @@ function image_downsize( $id, $size = 'medium' ) {
 	 * @param array|string $size     Size of image. Image size or array of width and height values (in that order).
 	 *                               Default 'medium'.
 	 */
-	if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) {
+	$out = apply_filters( 'image_downsize', false, $id, $size );
+	if ( $out ) {
 		return $out;
 	}
 
 	$img_url          = wp_get_attachment_url( $id );
 	$meta             = wp_get_attachment_metadata( $id );
-	$width            = $height = 0;
+	$height           = 0;
+	$width            = $height;
 	$is_intermediate  = false;
 	$img_url_basename = wp_basename( $img_url );
+	$intermediate     = image_get_intermediate_size( $id, $size );
+	$thumb_file       = wp_get_attachment_thumb_file( $id );
+	$info             = $thumb_file && getimagesize( $thumb_file );
 
 	// If the file isn't an image, attempt to replace its URL with a rendered image from its meta.
 	// Otherwise, a non-image type could be returned.
@@ -219,14 +224,14 @@ function image_downsize( $id, $size = 'medium' ) {
 	}
 
 	// try for a new style intermediate size
-	if ( $intermediate = image_get_intermediate_size( $id, $size ) ) {
+	if ( $intermediate ) {
 		$img_url         = str_replace( $img_url_basename, $intermediate['file'], $img_url );
 		$width           = $intermediate['width'];
 		$height          = $intermediate['height'];
 		$is_intermediate = true;
-	} elseif ( $size == 'thumbnail' ) {
+	} elseif ( 'thumbnail' == $size ) {
 		// fall back to the old thumbnail
-		if ( ( $thumb_file = wp_get_attachment_thumb_file( $id ) ) && $info = getimagesize( $thumb_file ) ) {
+		if ( $thumb_file && $info ) {
 			$img_url         = str_replace( $img_url_basename, wp_basename( $thumb_file ), $img_url );
 			$width           = $info[0];
 			$height          = $info[1];
@@ -412,8 +417,10 @@ function wp_constrain_dimensions( $current_width, $current_height, $max_width =
 		return array( $current_width, $current_height );
 	}
 
-	$width_ratio = $height_ratio = 1.0;
-	$did_width   = $did_height = false;
+	$height_ratio = 1.0;
+	$width_ratio  = $height_ratio;
+	$did_height   = false;
+	$did_width    = $did_height;
 
 	if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) {
 		$width_ratio = $max_width / $current_width;
@@ -687,7 +694,8 @@ function wp_image_matches_ratio( $source_width, $source_height, $target_width, $
  * }
  */
 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
-	if ( ! $size || ! is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) || empty( $imagedata['sizes'] ) ) {
+	$imagedata = wp_get_attachment_metadata( $post_id );
+	if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
 		return false;
 	}
 
@@ -826,7 +834,8 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
 	if ( ! $image ) {
 		$src = false;
 
-		if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) {
+		if ( $icon && wp_mime_type_icon( $attachment_id ) ) {
+			$src = wp_mime_type_icon( $attachment_id );
 			/** This filter is documented in wp-includes/post.php */
 			$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
 
@@ -984,7 +993,7 @@ function _wp_get_attachment_relative_path( $file ) {
  *                    or false if the size doesn't exist.
  */
 function _wp_get_image_size_from_meta( $size_name, $image_meta ) {
-	if ( $size_name === 'full' ) {
+	if ( 'full' == $size_name ) {
 		return array(
 			absint( $image_meta['width'] ),
 			absint( $image_meta['height'] ),
@@ -1014,7 +1023,8 @@ function _wp_get_image_size_from_meta( $size_name, $image_meta ) {
  * @return string|bool A 'srcset' value string or false.
  */
 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
-	if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) {
+	$image = wp_get_attachment_image_src( $attachment_id, $size );
+	if ( ! $image ) {
 		return false;
 	}
 
@@ -1146,7 +1156,8 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
 
 		// If the file name is part of the `src`, we've confirmed a match.
 		if ( ! $src_matched && false !== strpos( $image_src, $dirname . $image['file'] ) ) {
-			$src_matched = $is_src = true;
+			$is_src      = true;
+			$src_matched = $is_src;
 		}
 
 		// Filter out images that are from previous edits.
@@ -1232,7 +1243,8 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
  * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
  */
 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) {
-	if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) {
+	$image = wp_get_attachment_image_src( $attachment_id, $size );
+	if ( ! $image ) {
 		return false;
 	}
 
@@ -1318,19 +1330,22 @@ function wp_make_content_images_responsive( $content ) {
 		return $content;
 	}
 
-	$selected_images = $attachment_ids = array();
+	$attachment_ids  = array();
+	$selected_images = $attachment_ids;
 
 	foreach ( $matches[0] as $image ) {
-		if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) &&
-			( $attachment_id = absint( $class_id[1] ) ) ) {
-
-			/*
-			 * If exactly the same image tag is used more than once, overwrite it.
-			 * All identical tags will be replaced later with 'str_replace()'.
-			 */
-			$selected_images[ $image ] = $attachment_id;
-			// Overwrite the ID when the same image is included more than once.
-			$attachment_ids[ $attachment_id ] = true;
+		if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) ) {
+			$attachment_id = absint( $class_id[1] );
+			if ( $attachment_id ) {
+
+				/*
+				 * If exactly the same image tag is used more than once, overwrite it.
+				 * All identical tags will be replaced later with 'str_replace()'.
+				 */
+				$selected_images[ $image ] = $attachment_id;
+				// Overwrite the ID when the same image is included more than once.
+				$attachment_ids[ $attachment_id ] = true;
+			}
 		}
 	}
 
@@ -1394,7 +1409,7 @@ function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) {
 		 */
 		$image_filename = wp_basename( $image_src );
 
-		if ( $image_filename === wp_basename( $image_meta['file'] ) ) {
+		if ( wp_basename( $image_meta['file'] ) === $image_filename ) {
 			$width  = (int) $image_meta['width'];
 			$height = (int) $image_meta['height'];
 		} else {
@@ -1539,7 +1554,7 @@ function img_caption_shortcode( $attr, $content = null ) {
 	 * @param string $content The image element, possibly wrapped in a hyperlink.
 	 */
 	$output = apply_filters( 'img_caption_shortcode', '', $attr, $content );
-	if ( $output != '' ) {
+	if ( '' != $output ) {
 		return $output;
 	}
 
@@ -1561,7 +1576,9 @@ function img_caption_shortcode( $attr, $content = null ) {
 		return $content;
 	}
 
-	$id = $caption_id = $describedby = '';
+	$describedby = '';
+	$caption_id  = $describedby
+	$id          = $caption_id;
 
 	if ( $atts['id'] ) {
 		$atts['id'] = sanitize_html_class( $atts['id'] );
@@ -1705,7 +1722,7 @@ function gallery_shortcode( $attr ) {
 	 * @param int    $instance Unique numeric ID of this gallery shortcode instance.
 	 */
 	$output = apply_filters( 'post_gallery', '', $attr, $instance );
-	if ( $output != '' ) {
+	if ( '' != $output ) {
 		return $output;
 	}
 
@@ -1878,12 +1895,12 @@ function gallery_shortcode( $attr ) {
 				</{$captiontag}>";
 		}
 		$output .= "</{$itemtag}>";
-		if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
+		if ( ! $html5 && $columns > 0 && 0 == ++$i % $columns ) {
 			$output .= '<br style="clear: both" />';
 		}
 	}
 
-	if ( ! $html5 && $columns > 0 && $i % $columns !== 0 ) {
+	if ( ! $html5 && $columns > 0 && $i % 0 !== $columns ) {
 		$output .= "
 			<br style='clear: both' />";
 	}
@@ -2025,7 +2042,7 @@ function wp_playlist_shortcode( $attr ) {
 	 * @param int    $instance Unique numeric ID of this playlist shortcode instance.
 	 */
 	$output = apply_filters( 'post_playlist', '', $attr, $instance );
-	if ( $output != '' ) {
+	if ( '' != $output ) {
 		return $output;
 	}
 
@@ -2049,7 +2066,7 @@ function wp_playlist_shortcode( $attr ) {
 
 	$id = intval( $atts['id'] );
 
-	if ( $atts['type'] !== 'audio' ) {
+	if ( 'audio' !== $atts['type'] ) {
 		$atts['type'] = 'video';
 	}
 
@@ -2582,7 +2599,8 @@ function wp_video_shortcode( $attr, $content = '' ) {
 		}
 	}
 
-	$is_vimeo      = $is_youtube = false;
+	$is_youtube    = false;
+	$is_vimeo      = $is_youtube
 	$yt_pattern    = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';
 	$vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#';
 
@@ -2891,7 +2909,8 @@ function get_attachment_taxonomies( $attachment, $output = 'names' ) {
 
 	$taxonomies = array();
 	foreach ( $objects as $object ) {
-		if ( $taxes = get_object_taxonomies( $object, $output ) ) {
+		$taxes = get_object_taxonomies( $object, $output );
+		if ( $taxes ) {
 			$taxonomies = array_merge( $taxonomies, $taxes );
 		}
 	}
@@ -3193,7 +3212,8 @@ function wp_plupload_default_settings() {
  * @return array|void Array of attachment details.
  */
 function wp_prepare_attachment_for_js( $attachment ) {
-	if ( ! $attachment = get_post( $attachment ) ) {
+	$attachment = get_post( $attachment );
+	if ( ! $attachment ) {
 		return;
 	}
 
@@ -3316,7 +3336,8 @@ function wp_prepare_attachment_for_js( $attachment ) {
 		foreach ( $possible_sizes as $size => $label ) {
 
 			/** This filter is documented in wp-includes/media.php */
-			if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) {
+			$downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size )
+			if ( $downsize ) {
 				if ( empty( $downsize[3] ) ) {
 					continue;
 				}
@@ -3576,10 +3597,18 @@ function wp_enqueue_media( $args = array() ) {
 		$month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year );
 	}
 
+	// Filter to show only available mime types.
+	$avail_post_mime_types = get_available_post_mime_types( 'attachment' );
+	$mime_types            = wp_list_pluck( get_post_mime_types(), 0 );
+	foreach ( $mime_types as $mime_type => $label ) {
+		if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
+			unset( $mime_types[ $mime_type ] );
+		}
+	}
 	$settings = array(
 		'tabs'             => $tabs,
 		'tabUrl'           => add_query_arg( array( 'chromeless' => true ), admin_url( 'media-upload.php' ) ),
-		'mimeTypes'        => wp_list_pluck( get_post_mime_types(), 0 ),
+		'mimeTypes'        => $mime_types,
 		/** This filter is documented in wp-admin/includes/media.php */
 		'captions'         => ! apply_filters( 'disable_captions', '' ),
 		'nonce'            => array(
@@ -3815,7 +3844,8 @@ function wp_enqueue_media( $args = array() ) {
  * @return array Found attachments.
  */
 function get_attached_media( $type, $post = 0 ) {
-	if ( ! $post = get_post( $post ) ) {
+	$post = get_post( $post );
+	if ( ! $post ) {
 		return array();
 	}
 
@@ -3905,7 +3935,8 @@ function get_media_embedded_in_content( $content, $types = null ) {
  *               from the expanded shortcode.
  */
 function get_post_galleries( $post, $html = true ) {
-	if ( ! $post = get_post( $post ) ) {
+	$post = get_post( $post );
+	if ( ! $post ) {
 		return array();
 	}
 
@@ -4026,12 +4057,12 @@ function get_post_gallery_images( $post = 0 ) {
  * @param WP_Post $attachment Attachment object.
  */
 function wp_maybe_generate_attachment_metadata( $attachment ) {
-	if ( empty( $attachment ) || ( empty( $attachment->ID ) || ! $attachment_id = (int) $attachment->ID ) ) {
+	if ( empty( $attachment ) || ( empty( $attachment->ID ) || ! (int) $attachment->ID ) ) {
 		return;
 	}
-
-	$file = get_attached_file( $attachment_id );
-	$meta = wp_get_attachment_metadata( $attachment_id );
+	$attachment_id = (int) $attachment->ID;
+	$file          = get_attached_file( $attachment_id );
+	$meta          = wp_get_attachment_metadata( $attachment_id );
 	if ( empty( $meta ) && file_exists( $file ) ) {
 		$_meta             = get_post_meta( $attachment_id );
 		$regeneration_lock = 'wp_generating_att_' . $attachment_id;
@@ -4071,11 +4102,12 @@ function attachment_url_to_postid( $url ) {
 		$path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
 	}
 
-	$sql     = $wpdb->prepare(
-		"SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
-		$path
+	$post_id = $wpdb->get_var(
+		$wpdb->prepare(
+			"SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
+			$path
+		)
 	);
-	$post_id = $wpdb->get_var( $sql );
 
 	/**
 	 * Filters an attachment id found by URL.
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
index 88b9a46475..94a1c48c69 100644
--- tests/phpunit/tests/functions.php
+++ tests/phpunit/tests/functions.php
@@ -465,6 +465,56 @@ class Tests_Functions extends WP_UnitTestCase {
 		$this->assertNotEmpty( $mimes );
 	}
 
+	function check_settings_for_single( $settings ) {
+		$this->assertEquals( array( 'image' ), array_keys( $settings['mimeTypes'] ) );
+		return $settings;
+	}
+
+	function check_settings_for_multiple( $settings ) {
+		$this->assertEquals( array( 'image', 'audio' ), array_keys( $settings['mimeTypes'] ) );
+		return $settings;
+	}
+
+	/**
+	 * Test that the media grid uses the correct available single media type.
+	 * @ticket 43658
+	 */
+	function test_wp_enqueue_media_single_mime_type() {
+		$filename      = DIR_TESTDATA . '/images/test-image.jpg';
+		$contents      = file_get_contents( $filename );
+		$upload        = wp_upload_bits( basename( $filename ), null, $contents );
+		$attachment_id = $this->_make_attachment( $upload );
+
+		add_filter(
+			'media_view_settings',
+			array( $this, 'check_settings_for_single' )
+		);
+		wp_enqueue_media();
+		remove_all_filters( 'media_view_settings' );
+	}
+
+	/**
+	 * Test that the media grid uses the correct available multiple media types.
+	 * @ticket 43658
+	 */
+	function test_wp_enqueue_media_multiple_mime_types() {
+		$filename      = DIR_TESTDATA . '/images/test-image.jpg';
+		$contents      = file_get_contents( $filename );
+		$upload        = wp_upload_bits( basename( $filename ), null, $contents );
+		$attachment_id = $this->_make_attachment( $upload );
+
+		$filename      = DIR_TESTDATA . '/uploads/small-audio.mp3';
+		$contents      = file_get_contents( $filename );
+		$upload        = wp_upload_bits( basename( $filename ), null, $contents );
+		$attachment_id = $this->_make_attachment( $upload );
+
+		add_filter(
+			'media_view_settings',
+			array( $this, 'check_settings_for_multiple' )
+		);
+		wp_enqueue_media();
+	}
+
 	/**
 	 * @ticket 21594
 	 */
