diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index ece84326f7..47ed3697bb 100644
--- a/src/wp-includes/media.php
+++ b/src/wp-includes/media.php
@@ -175,8 +175,9 @@ function image_hwstring( $width, $height ) {
  * elements that are normally returned from the function.
  *
  * @since 2.5.0
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
- * @param int          $id   Attachment ID for image.
+ * @param int|WP_Post  $attachment Attachment post or attachment ID for image.
  * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
  *                           of width and height values in pixels (in that order). Default 'medium'.
  * @return array|false {
@@ -188,8 +189,15 @@ function image_hwstring( $width, $height ) {
  *     @type bool   $3 Whether the image is a resized image.
  * }
  */
-function image_downsize( $id, $size = 'medium' ) {
-	$is_image = wp_attachment_is_image( $id );
+function image_downsize( $attachment, $size = 'medium' ) {
+
+	$post = get_post( $attachment );
+
+	if ( ! $post || 'attachment' !== $post->post_type ) {
+		return false;
+	}
+
+	$is_image = wp_attachment_is_image( $post );
 
 	/**
 	 * Filters whether to preempt the output of image_downsize().
@@ -198,20 +206,22 @@ function image_downsize( $id, $size = 'medium' ) {
 	 * down-sizing the image, returning that value instead.
 	 *
 	 * @since 2.5.0
+	 * @since 5.6.0 add $post parameter.
 	 *
 	 * @param bool|array   $downsize Whether to short-circuit the image downsize.
 	 * @param int          $id       Attachment ID for image.
 	 * @param string|int[] $size     Requested image size. Can be any registered image size name, or
 	 *                               an array of width and height values in pixels (in that order).
+	 * @param WP_Post      $post     Attachment post object.
 	 */
-	$out = apply_filters( 'image_downsize', false, $id, $size );
+	$out = apply_filters( 'image_downsize', false, $post->ID, $size, $post );
 
 	if ( $out ) {
 		return $out;
 	}
 
-	$img_url          = wp_get_attachment_url( $id );
-	$meta             = wp_get_attachment_metadata( $id );
+	$img_url          = wp_get_attachment_url( $post );
+	$meta             = wp_get_attachment_metadata( $post );
 	$width            = 0;
 	$height           = 0;
 	$is_intermediate  = false;
@@ -231,7 +241,7 @@ function image_downsize( $id, $size = 'medium' ) {
 	}
 
 	// Try for a new style intermediate size.
-	$intermediate = image_get_intermediate_size( $id, $size );
+	$intermediate = image_get_intermediate_size( $post, $size );
 
 	if ( $intermediate ) {
 		$img_url         = str_replace( $img_url_basename, $intermediate['file'], $img_url );
@@ -240,7 +250,7 @@ function image_downsize( $id, $size = 'medium' ) {
 		$is_intermediate = true;
 	} elseif ( 'thumbnail' === $size ) {
 		// Fall back to the old thumbnail.
-		$thumb_file = wp_get_attachment_thumb_file( $id );
+		$thumb_file = wp_get_attachment_thumb_file( $post );
 		$info       = null;
 
 		if ( $thumb_file ) {
@@ -361,8 +371,9 @@ function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
  * content.
  *
  * @since 2.5.0
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
- * @param int          $id    Attachment ID.
+ * @param int|WP_Post  $attachment Attachment post or post ID.
  * @param string       $alt   Image description for the alt attribute.
  * @param string       $title Image description for the title attribute.
  * @param string       $align Part of the class name for aligning the image.
@@ -370,8 +381,15 @@ function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
  *                           width and height values in pixels (in that order). Default 'medium'.
  * @return string HTML IMG element for given image attachment
  */
-function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
+function get_image_tag( $attachment, $alt, $title, $align, $size = 'medium' ) {
+
+	$post = get_post( $attachment );
 
+	if ( ! $post || 'attachment' !== $post->post_type ) {
+		return '';
+	}
+
+	$id = $post->ID;
 	list( $img_src, $width, $height ) = image_downsize( $id, $size );
 	$hwstring                         = image_hwstring( $width, $height );
 
@@ -383,14 +401,16 @@ function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
 	 * Filters the value of the attachment's image tag class attribute.
 	 *
 	 * @since 2.6.0
+	 * @since 5.6.0 add $post parameter.
 	 *
 	 * @param string       $class CSS class name or space-separated list of classes.
 	 * @param int          $id    Attachment ID.
 	 * @param string       $align Part of the class name for aligning the image.
 	 * @param string|int[] $size  Requested image size. Can be any registered image size name, or
 	 *                            an array of width and height values in pixels (in that order).
+	 * @param WP_Post      $post  Attachment post object.
 	 */
-	$class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );
+	$class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size, $post );
 
 	$html = '<img src="' . esc_attr( $img_src ) . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
 
@@ -398,6 +418,7 @@ function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
 	 * Filters the HTML content for the image tag.
 	 *
 	 * @since 2.6.0
+	 * @since 5.6.0 add $post parameter.
 	 *
 	 * @param string       $html  HTML content for the image.
 	 * @param int          $id    Attachment ID.
@@ -406,8 +427,9 @@ function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
 	 * @param string       $align Part of the class name for aligning the image.
 	 * @param string|int[] $size  Requested image size. Can be any registered image size name, or
 	 *                            an array of width and height values in pixels (in that order).
+	 * @param WP_Post      $post  Attachment post object.
 	 */
-	return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
+	return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size, $post );
 }
 
 /**
@@ -740,10 +762,11 @@ function wp_image_matches_ratio( $source_width, $source_height, $target_width, $
  * browser scale down the image.
  *
  * @since 2.5.0
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
- * @param int          $post_id Attachment ID.
- * @param string|int[] $size    Optional. Image size. Accepts any registered image size name, or an array
- *                              of width and height values in pixels (in that order). Default 'thumbnail'.
+ * @param int|WP_Post  $attachment Attachment post or post ID.
+ * @param string|int[] $size       Optional. Image size. Accepts any registered image size name, or an array
+ *                                  of width and height values in pixels (in that order). Default 'thumbnail'.
  * @return array|false {
  *     Array of file relative path, width, and height on success. Additionally includes absolute
  *     path and URL if registered size is passed to `$size` parameter. False on failure.
@@ -755,10 +778,12 @@ function wp_image_matches_ratio( $source_width, $source_height, $target_width, $
  *     @type string $url    URL of image.
  * }
  */
-function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
-	$imagedata = wp_get_attachment_metadata( $post_id );
+function image_get_intermediate_size( $attachment, $size = 'thumbnail' ) {
 
-	if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
+	$post = get_post( $attachment );
+	$imagedata = wp_get_attachment_metadata( $post );
+
+	if ( ! $size || ! $post || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
 		return false;
 	}
 
@@ -827,7 +852,7 @@ function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
 
 	// Include the full filesystem path of the intermediate file.
 	if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) {
-		$file_url     = wp_get_attachment_url( $post_id );
+		$file_url     = wp_get_attachment_url( $post );
 		$data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] );
 		$data['url']  = path_join( dirname( $file_url ), $data['file'] );
 	}
@@ -836,16 +861,18 @@ function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
 	 * Filters the output of image_get_intermediate_size()
 	 *
 	 * @since 4.4.0
+	 * @since 5.6.0 add $post parameter.
 	 *
 	 * @see image_get_intermediate_size()
 	 *
 	 * @param array        $data    Array of file relative path, width, and height on success. May also include
 	 *                              file absolute path and URL.
-	 * @param int          $post_id The ID of the image attachment.
+	 * @param int                   The ID of the image attachment.
 	 * @param string|int[] $size    Requested image size. Can be any registered image size name, or
 	 *                              an array of width and height values in pixels (in that order).
+	 * @param WP_Post      $post    Attachment post object.
 	 */
-	return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
+	return apply_filters( 'image_get_intermediate_size', $data, $post->ID, $size, $post );
 }
 
 /**
@@ -933,8 +960,9 @@ function wp_get_registered_image_subsizes() {
  * Retrieves an image to represent an attachment.
  *
  * @since 2.5.0
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
- * @param int          $attachment_id Image attachment ID.
+ * @param int|WP_Post  $attachment    Attachment post or post ID.
  * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
  *                                    width and height values in pixels (in that order). Default 'thumbnail'.
  * @param bool         $icon          Optional. Whether the image should fall back to a mime type icon. Default false.
@@ -947,8 +975,16 @@ function wp_get_registered_image_subsizes() {
  *     @type bool   $3 Whether the image is a resized image.
  * }
  */
-function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
+function wp_get_attachment_image_src( $attachment, $size = 'thumbnail', $icon = false ) {
+
+	$post = get_post( $attachment );
+
+	if ( ! $post || 'attachment' !== $post->post_type ) {
+		return false;
+	}
+
 	// Get a thumbnail or intermediate image if there is one.
+	$attachment_id = $post->ID;
 	$image = image_downsize( $attachment_id, $size );
 	if ( ! $image ) {
 		$src = false;
@@ -973,6 +1009,7 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
 	 * Filters the attachment image source result.
 	 *
 	 * @since 4.3.0
+	 * @since 5.6.0 add $post parameter.
 	 *
 	 * @param array|false  $image         {
 	 *     Array of image data, or boolean false if no image is available.
@@ -986,8 +1023,9 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
 	 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
 	 *                                    an array of width and height values in pixels (in that order).
 	 * @param bool         $icon          Whether the image should be treated as an icon.
+	 * @param WP_Post      $post          Attachment post object.
 	 */
-	return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
+	return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon, $post );
 }
 
 /**
@@ -1001,8 +1039,9 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
  * @since 2.5.0
  * @since 4.4.0 The `$srcset` and `$sizes` attributes were added.
  * @since 5.5.0 The `$loading` attribute was added.
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
- * @param int          $attachment_id Image attachment ID.
+ * @param int|WP_Post  $attachment    Attachment post or post ID.
  * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array
  *                                    of width and height values in pixels (in that order). Default 'thumbnail'.
  * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
@@ -1022,25 +1061,25 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
  * }
  * @return string HTML img element or empty string on failure.
  */
-function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
+function wp_get_attachment_image( $attachment, $size = 'thumbnail', $icon = false, $attr = '' ) {
 	$html  = '';
-	$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
+	$image = wp_get_attachment_image_src( $attachment, $size, $icon );
 
 	if ( $image ) {
 		list( $src, $width, $height ) = $image;
 
-		$attachment = get_post( $attachment_id );
+		$post = get_post( $attachment );
 		$hwstring   = image_hwstring( $width, $height );
 		$size_class = $size;
 
 		if ( is_array( $size_class ) ) {
-			$size_class = join( 'x', $size_class );
+			$size_class = implode( 'x', $size_class );
 		}
 
 		$default_attr = array(
 			'src'   => $src,
 			'class' => "attachment-$size_class size-$size_class",
-			'alt'   => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
+			'alt'   => trim( strip_tags( get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ) ),
 		);
 
 		// Add `loading` attribute.
@@ -1058,12 +1097,12 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f
 
 		// Generate 'srcset' and 'sizes' if not already present.
 		if ( empty( $attr['srcset'] ) ) {
-			$image_meta = wp_get_attachment_metadata( $attachment_id );
+			$image_meta = wp_get_attachment_metadata( $post );
 
 			if ( is_array( $image_meta ) ) {
 				$size_array = array( absint( $width ), absint( $height ) );
-				$srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id );
-				$sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id );
+				$srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $post->ID );
+				$sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $post->ID );
 
 				if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
 					$attr['srcset'] = $srcset;
@@ -1082,11 +1121,11 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f
 		 *
 		 * @param array        $attr       Array of attribute values for the image markup, keyed by attribute name.
 		 *                                 See wp_get_attachment_image().
-		 * @param WP_Post      $attachment Image attachment post.
+		 * @param WP_Post      $post       Image attachment post.
 		 * @param string|int[] $size       Requested image size. Can be any registered image size name, or
 		 *                                 an array of width and height values in pixels (in that order).
 		 */
-		$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
+		$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $post, $size );
 
 		$attr = array_map( 'esc_attr', $attr );
 		$html = rtrim( "<img $hwstring" );
@@ -1104,16 +1143,16 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f
 /**
  * Get the URL of an image attachment.
  *
- * @since 4.4.0
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
- * @param int          $attachment_id Image attachment ID.
+ * @param int|WP_Post  $attachment    Attachment post or post ID.
  * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
  *                                    width and height values in pixels (in that order). Default 'thumbnail'.
  * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
  * @return string|false Attachment URL or false if no image is available.
  */
-function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
-	$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
+function wp_get_attachment_image_url( $attachment, $size = 'thumbnail', $icon = false ) {
+	$image = wp_get_attachment_image_src( $attachment, $size, $icon );
 	return isset( $image['0'] ) ? $image['0'] : false;
 }
 
@@ -1179,25 +1218,33 @@ function _wp_get_image_size_from_meta( $size_name, $image_meta ) {
  * Retrieves the value for an image attachment's 'srcset' attribute.
  *
  * @since 4.4.0
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
  * @see wp_calculate_image_srcset()
  *
- * @param int          $attachment_id Image attachment ID.
+ * @param int|WP_Post  $attachment    Attachment post or post ID.
  * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
  *                                    width and height values in pixels (in that order). Default 'medium'.
  * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
  *                                    Default null.
  * @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 );
+function wp_get_attachment_image_srcset( $attachment, $size = 'medium', $image_meta = null ) {
+
+	$post = get_post( $attachment );
+
+	if ( ! $post || 'attachment' !== $post->post_type ) {
+		return false;
+	}
+
+	$image = wp_get_attachment_image_src( $post, $size );
 
 	if ( ! $image ) {
 		return false;
 	}
 
 	if ( ! is_array( $image_meta ) ) {
-		$image_meta = wp_get_attachment_metadata( $attachment_id );
+		$image_meta = wp_get_attachment_metadata( $post );
 	}
 
 	$image_src  = $image[0];
@@ -1206,7 +1253,7 @@ function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $imag
 		absint( $image[2] ),
 	);
 
-	return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
+	return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $post->ID );
 }
 
 /**
@@ -1423,22 +1470,29 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
  *
  * @see wp_calculate_image_sizes()
  *
- * @param int          $attachment_id Image attachment ID.
+ * @param int|WP_Post  $attachment    Attachment post or post ID.
  * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
  *                                    width and height values in pixels (in that order). Default 'medium'.
  * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
  *                                    Default null.
  * @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 );
+function wp_get_attachment_image_sizes( $attachment, $size = 'medium', $image_meta = null ) {
+
+	$post = get_post( $attachment );
+
+	if ( ! $post || 'attachment' !== $post->post_type ) {
+		return false;
+	}
+
+	$image = wp_get_attachment_image_src( $post, $size );
 
 	if ( ! $image ) {
 		return false;
 	}
 
 	if ( ! is_array( $image_meta ) ) {
-		$image_meta = wp_get_attachment_metadata( $attachment_id );
+		$image_meta = wp_get_attachment_metadata( $post );
 	}
 
 	$image_src  = $image[0];
@@ -1447,7 +1501,7 @@ function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image
 		absint( $image[2] ),
 	);
 
-	return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );
+	return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $post->ID );
 }
 
 /**
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index 575a2fbaea..7cf9d10026 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -5975,9 +5975,11 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
  * Retrieves attachment metadata for attachment ID.
  *
  * @since 2.1.0
+ * @since 5.6.0 allow WP_Post object to be passed.
+ *
+ * @param int|WP_Post   $attachment    Attachment post or post ID.
+ * @param bool          $unfiltered    Optional. If true, filters are not run. Default false.
  *
- * @param int  $attachment_id Attachment post ID. Defaults to global $post.
- * @param bool $unfiltered    Optional. If true, filters are not run. Default false.
  * @return array|false {
  *     Attachment metadata. False on failure.
  *
@@ -5989,10 +5991,14 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
  *     @type array  $image_meta Image metadata.
  * }
  */
-function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
-	$attachment_id = (int) $attachment_id;
+function wp_get_attachment_metadata( $attachment, $unfiltered = false ) {
+	$post = get_post( $attachment );
 
-	$data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
+	if ( ! $post || 'attachment' !== $post->post_type ) {
+		return false;
+	}
+
+	$data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );
 
 	if ( empty( $data ) ) {
 		return false;
@@ -6006,28 +6012,31 @@ function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
 	 * Filters the attachment meta data.
 	 *
 	 * @since 2.1.0
+	 * @since 5.6.0 add $post parameter.
 	 *
-	 * @param array|bool $data          Array of meta data for the given attachment, or false
+	 * @param array|bool $data  Array of meta data for the given attachment, or false
 	 *                                  if the object does not exist.
-	 * @param int        $attachment_id Attachment post ID.
+	 * @param int               Attachment post ID.
+	 * @param WP_Post    $post  Attachment WP_Post object.
 	 */
-	return apply_filters( 'wp_get_attachment_metadata', $data, $attachment_id );
+	return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID, $post );
 }
 
 /**
  * Updates metadata for an attachment.
  *
  * @since 2.1.0
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
- * @param int   $attachment_id Attachment post ID.
- * @param array $data          Attachment meta data.
+ * @param int|WP_Post  $attachment    Attachment post or post ID.
+ * @param array        $data          Attachment meta data.
  * @return int|bool False if $post is invalid.
  */
-function wp_update_attachment_metadata( $attachment_id, $data ) {
-	$attachment_id = (int) $attachment_id;
+function wp_update_attachment_metadata( $attachment, $data ) {
 
-	$post = get_post( $attachment_id );
-	if ( ! $post ) {
+	$post = get_post( $attachment );
+
+	if ( ! $post || 'attachment' !== $post->post_type ) {
 		return false;
 	}
 
@@ -6035,37 +6044,37 @@ function wp_update_attachment_metadata( $attachment_id, $data ) {
 	 * Filters the updated attachment meta data.
 	 *
 	 * @since 2.1.0
+	 * @since 5.6.0 add $post parameter.
 	 *
-	 * @param array $data          Array of updated attachment meta data.
-	 * @param int   $attachment_id Attachment post ID.
+	 * @param array   $data          Array of updated attachment meta data.
+	 * @param int     $attachment_id Attachment post ID.
+	 * @param WP_Post $attachment    Attachment WP_Post object.
 	 */
-	$data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
+	$data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID, $post );
 	if ( $data ) {
 		return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
-	} else {
-		return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
 	}
+
+	return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
 }
 
 /**
  * Retrieve the URL for an attachment.
  *
  * @since 2.1.0
+ * @since 5.6.0 allow WP_Post object to be passed.
  *
  * @global string $pagenow
  *
- * @param int $attachment_id Optional. Attachment post ID. Defaults to global $post.
+ * @param int|WP_Post   $attachment    Attachment post or post ID.
+ *
  * @return string|false Attachment URL, otherwise false.
  */
-function wp_get_attachment_url( $attachment_id = 0 ) {
-	$attachment_id = (int) $attachment_id;
+function wp_get_attachment_url( $attachment ) {
 
-	$post = get_post( $attachment_id );
-	if ( ! $post ) {
-		return false;
-	}
+	$post = get_post( $attachment );
 
-	if ( 'attachment' !== $post->post_type ) {
+	if ( ! $post || 'attachment' !== $post->post_type ) {
 		return false;
 	}
 
@@ -6107,11 +6116,13 @@ function wp_get_attachment_url( $attachment_id = 0 ) {
 	 * Filters the attachment URL.
 	 *
 	 * @since 2.1.0
+	 * @since 5.6.0 add $post parameter.
 	 *
-	 * @param string $url           URL for the given attachment.
-	 * @param int    $attachment_id Attachment post ID.
+	 * @param string  $url              URL for the given attachment.
+	 * @param int     $attachment_id    Attachment post ID.
+	 * @param WP_Post $post             Attachment WP_Post object.
 	 */
-	$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
+	$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID, $post );
 
 	if ( empty( $url ) ) {
 		return false;
@@ -6125,17 +6136,15 @@ function wp_get_attachment_url( $attachment_id = 0 ) {
  *
  * @since 4.6.0
  *
- * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
+ * @param int|WP_Post $attachment Attachment post or post ID.
+ *
  * @return string|false False on failure. Attachment caption on success.
  */
-function wp_get_attachment_caption( $post_id = 0 ) {
-	$post_id = (int) $post_id;
-	$post    = get_post( $post_id );
-	if ( ! $post ) {
-		return false;
-	}
+function wp_get_attachment_caption( $attachment ) {
 
-	if ( 'attachment' !== $post->post_type ) {
+	$post = get_post( $attachment );
+
+	if ( ! $post || 'attachment' !== $post->post_type ) {
 		return false;
 	}
 
@@ -6145,25 +6154,30 @@ function wp_get_attachment_caption( $post_id = 0 ) {
 	 * Filters the attachment caption.
 	 *
 	 * @since 4.6.0
+	 * @since 5.6.0 add $post parameter.
 	 *
 	 * @param string $caption Caption for the given attachment.
-	 * @param int    $post_id Attachment ID.
+	 * @param int    $attachment_id Attachment ID.
+	 * @param WP_Post $attachment Attachment WP_Post object.
 	 */
-	return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );
+	return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID, $post );
 }
 
 /**
  * Retrieve thumbnail for an attachment.
  *
  * @since 2.1.0
+ * @since 5.6.0 allow WP_Post object to be passed.
+ *
+ * @param int|WP_Post $attachment Attachment post or post ID. Defaults to the global post.
  *
- * @param int $post_id Optional. Attachment ID. Default 0.
  * @return string|false False on failure. Thumbnail file path on success.
  */
-function wp_get_attachment_thumb_file( $post_id = 0 ) {
-	$post_id = (int) $post_id;
-	$post    = get_post( $post_id );
-	if ( ! $post ) {
+function wp_get_attachment_thumb_file( $attachment ) {
+
+	$post = get_post( $attachment );
+
+	if ( ! $post || 'attachment' !== $post->post_type ) {
 		return false;
 	}
 
@@ -6181,11 +6195,13 @@ function wp_get_attachment_thumb_file( $post_id = 0 ) {
 			 * Filters the attachment thumbnail file path.
 			 *
 			 * @since 2.1.0
+			 * @since 5.6.0 add $post parameter.
 			 *
-			 * @param string $thumbfile File path to the attachment thumbnail.
-			 * @param int    $post_id   Attachment ID.
+			 * @param string  $thumbfile       File path to the attachment thumbnail.
+			 * @param int     $attachment_id   Attachment ID.
+			 * @param WP_Post $post            Attachment post object.
 			 */
-			return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
+			return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID, $post );
 		}
 	}
 	return false;
@@ -6195,14 +6211,17 @@ function wp_get_attachment_thumb_file( $post_id = 0 ) {
  * Retrieve URL for an attachment thumbnail.
  *
  * @since 2.1.0
+ * @since 5.6.0 allow WP_Post object to be passed.
+ *
+ * @param int|WP_Post          $attachment    Attachment post or post ID.
  *
- * @param int $post_id Optional. Attachment ID. Default 0.
  * @return string|false False on failure. Thumbnail URL on success.
  */
-function wp_get_attachment_thumb_url( $post_id = 0 ) {
-	$post_id = (int) $post_id;
-	$post    = get_post( $post_id );
-	if ( ! $post ) {
+function wp_get_attachment_thumb_url( $attachment ) {
+
+	$post = get_post( $attachment );
+
+	if ( ! $post || 'attachment' !== $post->post_type ) {
 		return false;
 	}
 
@@ -6211,7 +6230,7 @@ function wp_get_attachment_thumb_url( $post_id = 0 ) {
 		return false;
 	}
 
-	$sized = image_downsize( $post_id, 'thumbnail' );
+	$sized = image_downsize( $post->ID, 'thumbnail' );
 	if ( $sized ) {
 		return $sized[0];
 	}
@@ -6227,11 +6246,13 @@ function wp_get_attachment_thumb_url( $post_id = 0 ) {
 	 * Filters the attachment thumbnail URL.
 	 *
 	 * @since 2.1.0
+	 * @since 5.6.0 add $post parameter.
 	 *
-	 * @param string $url     URL for the attachment thumbnail.
-	 * @param int    $post_id Attachment ID.
+	 * @param string  $url              URL for the attachment thumbnail.
+	 * @param int     $attachment_id    Attachment ID.
+	 * @param WP_Post $post             Attachment post object.
 	 */
-	return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
+	return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID, $post );
 }
 
 /**
@@ -6244,8 +6265,10 @@ function wp_get_attachment_thumb_url( $post_id = 0 ) {
  * @return bool True if one of the accepted types, false otherwise.
  */
 function wp_attachment_is( $type, $post = null ) {
+
 	$post = get_post( $post );
-	if ( ! $post ) {
+
+	if ( ! $post  || 'attachment' !== $post->post_type ) {
 		return false;
 	}
 
