Index: src/js/media/views/attachments/browser.js
===================================================================
--- src/js/media/views/attachments/browser.js	(revision 45756)
+++ src/js/media/views/attachments/browser.js	(working copy)
@@ -163,19 +163,21 @@
 				priority: -90
 			}).render() );
 
-			// DateFilter is a <select>, screen reader text needs to be rendered before
-			this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
-				value: l10n.filterByDate,
-				attributes: {
-					'for': 'media-attachment-date-filters'
-				},
-				priority: -75
-			}).render() );
-			this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
-				controller: this.controller,
-				model:      this.collection.props,
-				priority: -75
-			}).render() );
+			if ( showMonths ) {
+				// DateFilter is a <select>, screen reader text needs to be rendered before
+				this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
+					value: l10n.filterByDate,
+					attributes: {
+						'for': 'media-attachment-date-filters'
+					},
+					priority: -75
+				}).render() );
+				this.toolbar.set( 'dateFilter', new wp.media.view.DateFilter({
+					controller: this.controller,
+					model:      this.collection.props,
+					priority: -75
+				}).render() );
+			}
 
 			// BulkSelection is a <div> with subviews, including screen reader text
 			this.toolbar.set( 'selectModeToggleButton', new wp.media.view.SelectModeToggleButton({
@@ -284,7 +286,7 @@
 				}).render() );
 			}
 
-		} else if ( this.options.date ) {
+		} else if ( showMonths && this.options.date ) {
 			// DateFilter is a <select>, screen reader text needs to be rendered before
 			this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
 				value: l10n.filterByDate,
Index: src/wp-includes/media.php
===================================================================
--- src/wp-includes/media.php	(revision 45756)
+++ src/wp-includes/media.php	(working copy)
@@ -17,11 +17,9 @@
  */
 function wp_get_additional_image_sizes() {
 	global $_wp_additional_image_sizes;
-
 	if ( ! $_wp_additional_image_sizes ) {
 		$_wp_additional_image_sizes = array();
 	}
-
 	return $_wp_additional_image_sizes;
 }
 
@@ -68,7 +66,7 @@
 	if ( is_array( $size ) ) {
 		$max_width  = $size[0];
 		$max_height = $size[1];
-	} elseif ( $size === 'thumb' || $size === 'thumbnail' ) {
+	} elseif ( $size == 'thumb' || $size == 'thumbnail' ) {
 		$max_width  = intval( get_option( 'thumbnail_size_w' ) );
 		$max_height = intval( get_option( 'thumbnail_size_h' ) );
 		// last chance thumbnail size defaults
@@ -76,11 +74,11 @@
 			$max_width  = 128;
 			$max_height = 96;
 		}
-	} elseif ( $size === 'medium' ) {
+	} elseif ( $size == 'medium' ) {
 		$max_width  = intval( get_option( 'medium_size_w' ) );
 		$max_height = intval( get_option( 'medium_size_h' ) );
 
-	} elseif ( $size === 'medium_large' ) {
+	} elseif ( $size == 'medium_large' ) {
 		$max_width  = intval( get_option( 'medium_large_size_w' ) );
 		$max_height = intval( get_option( 'medium_large_size_h' ) );
 
@@ -87,7 +85,7 @@
 		if ( intval( $content_width ) > 0 ) {
 			$max_width = min( intval( $content_width ), $max_width );
 		}
-	} elseif ( $size === 'large' ) {
+	} elseif ( $size == 'large' ) {
 		/*
 		 * 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
@@ -96,11 +94,10 @@
 		 */
 		$max_width  = intval( get_option( 'large_size_w' ) );
 		$max_height = intval( get_option( 'large_size_h' ) );
-
 		if ( intval( $content_width ) > 0 ) {
 			$max_width = min( intval( $content_width ), $max_width );
 		}
-	} elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ), true ) ) {
+	} elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
 		$max_width  = intval( $_wp_additional_image_sizes[ $size ]['width'] );
 		$max_height = intval( $_wp_additional_image_sizes[ $size ]['height'] );
 		// Only in admin. Assume that theme authors know what they're doing.
@@ -198,16 +195,13 @@
 	 * @param array|string $size     Size of image. Image size or array of width and height values (in that order).
 	 *                               Default 'medium'.
 	 */
-	$out = apply_filters( 'image_downsize', false, $id, $size );
-
-	if ( $out ) {
+	if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) {
 		return $out;
 	}
 
 	$img_url          = wp_get_attachment_url( $id );
 	$meta             = wp_get_attachment_metadata( $id );
-	$width            = 0;
-	$height           = 0;
+	$width            = $height = 0;
 	$is_intermediate  = false;
 	$img_url_basename = wp_basename( $img_url );
 
@@ -225,23 +219,14 @@
 	}
 
 	// try for a new style intermediate size
-	$intermediate = image_get_intermediate_size( $id, $size );
-
-	if ( $intermediate ) {
+	if ( $intermediate = image_get_intermediate_size( $id, $size ) ) {
 		$img_url         = str_replace( $img_url_basename, $intermediate['file'], $img_url );
 		$width           = $intermediate['width'];
 		$height          = $intermediate['height'];
 		$is_intermediate = true;
-	} elseif ( $size === 'thumbnail' ) {
+	} elseif ( $size == 'thumbnail' ) {
 		// fall back to the old thumbnail
-		$thumb_file = wp_get_attachment_thumb_file( $id );
-		$info       = null;
-
-		if ( $thumb_file ) {
-			$info = @getimagesize( $thumb_file );
-		}
-
-		if ( $thumb_file && $info ) {
+		if ( ( $thumb_file = wp_get_attachment_thumb_file( $id ) ) && $info = getimagesize( $thumb_file ) ) {
 			$img_url         = str_replace( $img_url_basename, wp_basename( $thumb_file ), $img_url );
 			$width           = $info[0];
 			$height          = $info[1];
@@ -248,7 +233,6 @@
 			$is_intermediate = true;
 		}
 	}
-
 	if ( ! $width && ! $height && isset( $meta['width'], $meta['height'] ) ) {
 		// any other type: use the real image
 		$width  = $meta['width'];
@@ -261,8 +245,8 @@
 
 		return array( $img_url, $width, $height, $is_intermediate );
 	}
+	return false;
 
-	return false;
 }
 
 /**
@@ -428,10 +412,8 @@
 		return array( $current_width, $current_height );
 	}
 
-	$width_ratio  = 1.0;
-	$height_ratio = 1.0;
-	$did_width    = false;
-	$did_height   = false;
+	$width_ratio = $height_ratio = 1.0;
+	$did_width   = $did_height = false;
 
 	if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) {
 		$width_ratio = $max_width / $current_width;
@@ -464,12 +446,12 @@
 	// Thus we look for dimensions that are one pixel shy of the max value and bump them up
 
 	// Note: $did_width means it is possible $smaller_ratio == $width_ratio.
-	if ( $did_width && $w === $max_width - 1 ) {
+	if ( $did_width && $w == $max_width - 1 ) {
 		$w = $max_width; // Round it up
 	}
 
 	// Note: $did_height means it is possible $smaller_ratio == $height_ratio.
-	if ( $did_height && $h === $max_height - 1 ) {
+	if ( $did_height && $h == $max_height - 1 ) {
 		$h = $max_height; // Round it up
 	}
 
@@ -538,7 +520,6 @@
 	 *                           An array can specify positioning of the crop area. Default false.
 	 */
 	$output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop );
-
 	if ( null !== $output ) {
 		return $output;
 	}
@@ -595,7 +576,7 @@
 	}
 
 	// if the resulting image would be the same size or larger we don't want to resize it
-	if ( $new_w >= $orig_w && $new_h >= $orig_h && intval( $dest_w ) !== intval( $orig_w ) && intval( $dest_h ) !== intval( $orig_h ) ) {
+	if ( $new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h ) {
 		return false;
 	}
 
@@ -706,9 +687,7 @@
  * }
  */
 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
-	$imagedata = wp_get_attachment_metadata( $post_id );
-
-	if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
+	if ( ! $size || ! is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) || empty( $imagedata['sizes'] ) ) {
 		return false;
 	}
 
@@ -725,7 +704,7 @@
 
 		foreach ( $imagedata['sizes'] as $_size => $data ) {
 			// If there's an exact match to an existing image size, short circuit.
-			if ( intval( $data['width'] ) === intval( $size[0] ) && intval( $data['height'] ) === intval( $size[1] ) ) {
+			if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) {
 				$candidates[ $data['width'] * $data['height'] ] = $data;
 				break;
 			}
@@ -806,11 +785,10 @@
  * @return array Returns a filtered array of image size strings.
  */
 function get_intermediate_image_sizes() {
-	$default_sizes    = array( 'thumbnail', 'medium', 'medium_large', 'large' );
-	$additional_sizes = wp_get_additional_image_sizes();
-
-	if ( ! empty( $additional_sizes ) ) {
-		$default_sizes = array_merge( $default_sizes, array_keys( $additional_sizes ) );
+	$_wp_additional_image_sizes = wp_get_additional_image_sizes();
+	$image_sizes                = array( 'thumbnail', 'medium', 'medium_large', 'large' ); // Standard sizes
+	if ( ! empty( $_wp_additional_image_sizes ) ) {
+		$image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
 	}
 
 	/**
@@ -818,68 +796,13 @@
 	 *
 	 * @since 2.5.0
 	 *
-	 * @param array $default_sizes An array of intermediate image sizes. Defaults
-	 *                             are 'thumbnail', 'medium', 'medium_large', 'large'.
+	 * @param array $image_sizes An array of intermediate image sizes. Defaults
+	 *                           are 'thumbnail', 'medium', 'medium_large', 'large'.
 	 */
-	return apply_filters( 'intermediate_image_sizes', $default_sizes );
+	return apply_filters( 'intermediate_image_sizes', $image_sizes );
 }
 
 /**
- * Returns a normalized list of all currently registered image sub-sizes.
- *
- * @since 5.3.0
- * @uses wp_get_additional_image_sizes()
- * @uses get_intermediate_image_sizes()
- *
- * @return array Associative array of the registered image sub-sizes.
- */
-function wp_get_registered_image_subsizes() {
-	$additional_sizes = wp_get_additional_image_sizes();
-	$all_sizes        = array();
-
-	foreach ( get_intermediate_image_sizes() as $size_name ) {
-		$size_data = array(
-			'width'  => 0,
-			'height' => 0,
-			'crop'   => false,
-		);
-
-		if ( isset( $additional_sizes[ $size_name ]['width'] ) ) {
-			// For sizes added by plugins and themes.
-			$size_data['width'] = intval( $additional_sizes[ $size_name ]['width'] );
-		} else {
-			// For default sizes set in options.
-			$size_data['width'] = intval( get_option( "{$size_name}_size_w" ) );
-		}
-
-		if ( isset( $additional_sizes[ $size_name ]['height'] ) ) {
-			$size_data['height'] = intval( $additional_sizes[ $size_name ]['height'] );
-		} else {
-			$size_data['height'] = intval( get_option( "{$size_name}_size_h" ) );
-		}
-
-		if ( empty( $size_data['width'] ) && empty( $size_data['height'] ) ) {
-			// This size isn't set.
-			continue;
-		}
-
-		if ( isset( $additional_sizes[ $size_name ]['crop'] ) ) {
-			$size_data['crop'] = $additional_sizes[ $size_name ]['crop'];
-		} else {
-			$size_data['crop'] = get_option( "{$size_name}_crop" );
-		}
-
-		if ( ! is_array( $size_data['crop'] ) || empty( $size_data['crop'] ) ) {
-			$size_data['crop'] = (bool) $size_data['crop'];
-		}
-
-		$all_sizes[ $size_name ] = $size_data;
-	}
-
-	return $all_sizes;
-}
-
-/**
  * Retrieve an image to represent an attachment.
  *
  * A mime icon for files, thumbnail or intermediate size for images.
@@ -903,16 +826,12 @@
 	if ( ! $image ) {
 		$src = false;
 
-		if ( $icon ) {
-			$src = wp_mime_type_icon( $attachment_id );
+		if ( $icon && $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' );
 
-			if ( $src ) {
-				/** This filter is documented in wp-includes/post.php */
-				$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
-
-				$src_file               = $icon_dir . '/' . wp_basename( $src );
-				list( $width, $height ) = @getimagesize( $src_file );
-			}
+			$src_file                = $icon_dir . '/' . wp_basename( $src );
+			@list( $width, $height ) = getimagesize( $src_file );
 		}
 
 		if ( $src && $width && $height ) {
@@ -1095,9 +1014,7 @@
  * @return string|bool A 'srcset' value string or false.
  */
 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
-	$image = wp_get_attachment_image_src( $attachment_id, $size );
-
-	if ( ! $image ) {
+	if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) {
 		return false;
 	}
 
@@ -1229,8 +1146,7 @@
 
 		// 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 = true;
-			$is_src      = true;
+			$src_matched = $is_src = true;
 		}
 
 		// Filter out images that are from previous edits.
@@ -1316,9 +1232,7 @@
  * @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 ) {
-	$image = wp_get_attachment_image_src( $attachment_id, $size );
-
-	if ( ! $image ) {
+	if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) {
 		return false;
 	}
 
@@ -1404,22 +1318,19 @@
 		return $content;
 	}
 
-	$selected_images = array();
-	$attachment_ids  = array();
+	$selected_images = $attachment_ids = array();
 
 	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 ( 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;
-			}
+			/*
+			 * 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;
 		}
 	}
 
@@ -1628,8 +1539,7 @@
 	 * @param string $content The image element, possibly wrapped in a hyperlink.
 	 */
 	$output = apply_filters( 'img_caption_shortcode', '', $attr, $content );
-
-	if ( ! empty( $output ) ) {
+	if ( $output != '' ) {
 		return $output;
 	}
 
@@ -1647,14 +1557,11 @@
 	);
 
 	$atts['width'] = (int) $atts['width'];
-
 	if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) {
 		return $content;
 	}
 
-	$id          = '';
-	$caption_id  = '';
-	$describedby = '';
+	$id = $caption_id = $describedby = '';
 
 	if ( $atts['id'] ) {
 		$atts['id'] = sanitize_html_class( $atts['id'] );
@@ -1696,7 +1603,6 @@
 	$caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content );
 
 	$style = '';
-
 	if ( $caption_width ) {
 		$style = 'style="width: ' . (int) $caption_width . 'px" ';
 	}
@@ -1799,8 +1705,7 @@
 	 * @param int    $instance Unique numeric ID of this gallery shortcode instance.
 	 */
 	$output = apply_filters( 'post_gallery', '', $attr, $instance );
-
-	if ( ! empty( $output ) ) {
+	if ( $output != '' ) {
 		return $output;
 	}
 
@@ -1945,11 +1850,9 @@
 	$output = apply_filters( 'gallery_style', $gallery_style . $gallery_div );
 
 	$i = 0;
-
 	foreach ( $attachments as $id => $attachment ) {
 
 		$attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "$selector-$id" ) : '';
-
 		if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) {
 			$image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr );
 		} elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) {
@@ -1957,21 +1860,17 @@
 		} else {
 			$image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr );
 		}
-
 		$image_meta = wp_get_attachment_metadata( $id );
 
 		$orientation = '';
-
 		if ( isset( $image_meta['height'], $image_meta['width'] ) ) {
 			$orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
 		}
-
 		$output .= "<{$itemtag} class='gallery-item'>";
 		$output .= "
 			<{$icontag} class='gallery-icon {$orientation}'>
 				$image_output
 			</{$icontag}>";
-
 		if ( $captiontag && trim( $attachment->post_excerpt ) ) {
 			$output .= "
 				<{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'>
@@ -1978,10 +1877,8 @@
 				" . wptexturize( $attachment->post_excerpt ) . "
 				</{$captiontag}>";
 		}
-
 		$output .= "</{$itemtag}>";
-
-		if ( ! $html5 && $columns > 0 && ++$i % $columns === 0 ) {
+		if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
 			$output .= '<br style="clear: both" />';
 		}
 	}
@@ -2128,8 +2025,7 @@
 	 * @param int    $instance Unique numeric ID of this playlist shortcode instance.
 	 */
 	$output = apply_filters( 'post_playlist', '', $attr, $instance );
-
-	if ( ! empty( $output ) ) {
+	if ( $output != '' ) {
 		return $output;
 	}
 
@@ -2439,7 +2335,6 @@
 	 * @param int    $instance Unique numeric ID of this audio shortcode instance.
 	 */
 	$override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instance );
-
 	if ( '' !== $override ) {
 		return $override;
 	}
@@ -2464,11 +2359,9 @@
 	$primary = false;
 	if ( ! empty( $atts['src'] ) ) {
 		$type = wp_check_filetype( $atts['src'], wp_get_mime_types() );
-
-		if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) {
+		if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) {
 			return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) );
 		}
-
 		$primary = true;
 		array_unshift( $default_types, 'src' );
 	} else {
@@ -2475,7 +2368,6 @@
 		foreach ( $default_types as $ext ) {
 			if ( ! empty( $atts[ $ext ] ) ) {
 				$type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() );
-
 				if ( strtolower( $type['ext'] ) === $ext ) {
 					$primary = true;
 				}
@@ -2485,7 +2377,6 @@
 
 	if ( ! $primary ) {
 		$audios = get_attached_media( 'audio', $post_id );
-
 		if ( empty( $audios ) ) {
 			return;
 		}
@@ -2492,7 +2383,6 @@
 
 		$audio       = reset( $audios );
 		$atts['src'] = wp_get_attachment_url( $audio->ID );
-
 		if ( empty( $atts['src'] ) ) {
 			return;
 		}
@@ -2508,7 +2398,6 @@
 	 * @param string $library Media library used for the audio shortcode.
 	 */
 	$library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' );
-
 	if ( 'mediaelement' === $library && did_action( 'init' ) ) {
 		wp_enqueue_style( 'wp-mediaelement' );
 		wp_enqueue_script( 'wp-mediaelement' );
@@ -2542,28 +2431,23 @@
 	}
 
 	$attr_strings = array();
-
 	foreach ( $html_atts as $k => $v ) {
 		$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
 	}
 
 	$html = '';
-
 	if ( 'mediaelement' === $library && 1 === $instance ) {
 		$html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
 	}
-
 	$html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) );
 
 	$fileurl = '';
 	$source  = '<source type="%s" src="%s" />';
-
 	foreach ( $default_types as $fallback ) {
 		if ( ! empty( $atts[ $fallback ] ) ) {
 			if ( empty( $fileurl ) ) {
 				$fileurl = $atts[ $fallback ];
 			}
-
 			$type  = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
 			$url   = add_query_arg( '_', $instance, $atts[ $fallback ] );
 			$html .= sprintf( $source, $type['type'], esc_url( $url ) );
@@ -2573,7 +2457,6 @@
 	if ( 'mediaelement' === $library ) {
 		$html .= wp_mediaelement_fallback( $fileurl );
 	}
-
 	$html .= '</audio>';
 
 	/**
@@ -2661,7 +2544,6 @@
 	 * @param int    $instance Unique numeric ID of this video shortcode instance.
 	 */
 	$override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instance );
-
 	if ( '' !== $override ) {
 		return $override;
 	}
@@ -2700,8 +2582,7 @@
 		}
 	}
 
-	$is_vimeo      = false;
-	$is_youtube    = false;
+	$is_vimeo      = $is_youtube = false;
 	$yt_pattern    = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';
 	$vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#';
 
@@ -2709,11 +2590,9 @@
 	if ( ! empty( $atts['src'] ) ) {
 		$is_vimeo   = ( preg_match( $vimeo_pattern, $atts['src'] ) );
 		$is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) );
-
 		if ( ! $is_youtube && ! $is_vimeo ) {
 			$type = wp_check_filetype( $atts['src'], wp_get_mime_types() );
-
-			if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) {
+			if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) {
 				return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) );
 			}
 		}
@@ -2934,7 +2813,7 @@
 	);
 
 	foreach ( $attachments as $k => $attachment ) {
-		if ( intval( $attachment->ID ) === intval( $post->ID ) ) {
+		if ( $attachment->ID == $post->ID ) {
 			break;
 		}
 	}
@@ -2987,7 +2866,6 @@
 	} elseif ( is_array( $attachment ) ) {
 		$attachment = (object) $attachment;
 	}
-
 	if ( ! is_object( $attachment ) ) {
 		return array();
 	}
@@ -3000,10 +2878,8 @@
 	if ( false !== strpos( $filename, '.' ) ) {
 		$objects[] = 'attachment:' . substr( $filename, strrpos( $filename, '.' ) + 1 );
 	}
-
 	if ( ! empty( $attachment->post_mime_type ) ) {
 		$objects[] = 'attachment:' . $attachment->post_mime_type;
-
 		if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
 			foreach ( explode( '/', $attachment->post_mime_type ) as $token ) {
 				if ( ! empty( $token ) ) {
@@ -3014,11 +2890,8 @@
 	}
 
 	$taxonomies = array();
-
 	foreach ( $objects as $object ) {
-		$taxes = get_object_taxonomies( $object, $output );
-
-		if ( $taxes ) {
+		if ( $taxes = get_object_taxonomies( $object, $output ) ) {
 			$taxonomies = array_merge( $taxonomies, $taxes );
 		}
 	}
@@ -3044,11 +2917,10 @@
  */
 function get_taxonomies_for_attachments( $output = 'names' ) {
 	$taxonomies = array();
-
 	foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
 		foreach ( $taxonomy->object_type as $object_type ) {
-			if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
-				if ( 'names' === $output ) {
+			if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
+				if ( 'names' == $output ) {
 					$taxonomies[] = $taxonomy->name;
 				} else {
 					$taxonomies[ $taxonomy->name ] = $taxonomy;
@@ -3321,13 +3193,11 @@
  * @return array|void Array of attachment details.
  */
 function wp_prepare_attachment_for_js( $attachment ) {
-	$attachment = get_post( $attachment );
-
-	if ( ! $attachment ) {
+	if ( ! $attachment = get_post( $attachment ) ) {
 		return;
 	}
 
-	if ( 'attachment' !== $attachment->post_type ) {
+	if ( 'attachment' != $attachment->post_type ) {
 		return;
 	}
 
@@ -3446,9 +3316,7 @@
 		foreach ( $possible_sizes as $size => $label ) {
 
 			/** This filter is documented in wp-includes/media.php */
-			$downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size );
-
-			if ( $downsize ) {
+			if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) {
 				if ( empty( $downsize[3] ) ) {
 					continue;
 				}
@@ -3560,8 +3428,8 @@
  * @since 3.5.0
  *
  * @global int       $content_width
- * @global wpdb      $wpdb          WordPress database abstraction object.
- * @global WP_Locale $wp_locale     WordPress date and time locale object.
+ * @global wpdb      $wpdb
+ * @global WP_Locale $wp_locale
  *
  * @param array $args {
  *     Arguments for enqueuing media scripts.
@@ -3675,38 +3543,44 @@
 	}
 
 	/**
-	 * Allows overriding the list of months displayed in the media library.
+	 * Allows showing or hiding the months select in the media library.
 	 *
-	 * By default (if this filter does not return an array), a query will be
-	 * run to determine the months that have media items.  This query can be
-	 * expensive for large media libraries, so it may be desirable for sites to
-	 * override this behavior.
+	 * By default, the months select will always be shown in the media library
+ 	 * and a list of months will be generated to populate the select with.
+ 	 * If `false` is returned the 'media_library_months_with_files' filter
+ 	 * will not be run and no select will be shown.
 	 *
 	 * @since 4.7.4
 	 *
 	 * @link https://core.trac.wordpress.org/ticket/31071
 	 *
+	 * @link https://core.trac.wordpress.org/ticket/41675
+	 *
 	 * @param array|null An array of objects with `month` and `year`
 	 *                   properties, or `null` (or any other non-array value)
 	 *                   for default behavior.
 	 */
+	$show_months_select = apply_filters( 'media_library_months_with_files', true );
+	$months = null;
 	$months = apply_filters( 'media_library_months_with_files', null );
-	if ( ! is_array( $months ) ) {
-		$months = $wpdb->get_results(
-			$wpdb->prepare(
-				"
-			SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
-			FROM $wpdb->posts
-			WHERE post_type = %s
-			ORDER BY post_date DESC
-		",
-				'attachment'
-			)
-		);
+	if ( $show_months_select === true ) {
+		if ( ! is_array( $months ) ) {
+			$months = $wpdb->get_results(
+				$wpdb->prepare(
+					"
+				SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
+				FROM $wpdb->posts
+				WHERE post_type = %s
+				ORDER BY post_date DESC
+			",
+					'attachment'
+				)
+			);
+		}
+		foreach ( $months as $month_year ) {
+			$month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year );
+		}
 	}
-	foreach ( $months as $month_year ) {
-		$month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year );
-	}
 
 	$settings = array(
 		'tabs'             => $tabs,
@@ -3730,6 +3604,7 @@
 		'embedMimes'       => $ext_mimes,
 		'contentWidth'     => $content_width,
 		'months'           => $months,
+		'showMonths'	   => $show_months_select,
 		'mediaTrash'       => MEDIA_TRASH ? 1 : 0,
 	);
 
@@ -3948,9 +3823,7 @@
  * @return array Found attachments.
  */
 function get_attached_media( $type, $post = 0 ) {
-	$post = get_post( $post );
-
-	if ( ! $post ) {
+	if ( ! $post = get_post( $post ) ) {
 		return array();
 	}
 
@@ -4040,9 +3913,7 @@
  *               from the expanded shortcode.
  */
 function get_post_galleries( $post, $html = true ) {
-	$post = get_post( $post );
-
-	if ( ! $post ) {
+	if ( ! $post = get_post( $post ) ) {
 		return array();
 	}
 
@@ -4163,22 +4034,19 @@
  * @param WP_Post $attachment Attachment object.
  */
 function wp_maybe_generate_attachment_metadata( $attachment ) {
-	if ( empty( $attachment ) || empty( $attachment->ID ) ) {
+	if ( empty( $attachment ) || ( empty( $attachment->ID ) || ! $attachment_id = (int) $attachment->ID ) ) {
 		return;
 	}
 
-	$attachment_id = (int) $attachment->ID;
-	$file          = get_attached_file( $attachment_id );
-	$meta          = wp_get_attachment_metadata( $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 );
-		$_lock = 'wp_generating_att_' . $attachment_id;
-
-		if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $_lock ) ) {
-			set_transient( $_lock, $file );
+		$_meta             = get_post_meta( $attachment_id );
+		$regeneration_lock = 'wp_generating_att_' . $attachment_id;
+		if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $regeneration_lock ) ) {
+			set_transient( $regeneration_lock, $file );
 			wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
-			delete_transient( $_lock );
+			delete_transient( $regeneration_lock );
 		}
 	}
 }
@@ -4211,11 +4079,10 @@
 		$path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
 	}
 
-	$sql = $wpdb->prepare(
+	$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( $sql );
 
 	/**
