Make WordPress Core

Ticket #37255: 37255.4.patch

File 37255.4.patch, 29.5 KB (added by Mista-Flo, 5 years ago)

Quickfix

  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index ece84326f7..47ed3697bb 100644
    a b function image_hwstring( $width, $height ) { 
    175175 * elements that are normally returned from the function.
    176176 *
    177177 * @since 2.5.0
     178 * @since 5.6.0 allow WP_Post object to be passed.
    178179 *
    179  * @param int          $id   Attachment ID for image.
     180 * @param int|WP_Post  $attachment Attachment post or attachment ID for image.
    180181 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
    181182 *                           of width and height values in pixels (in that order). Default 'medium'.
    182183 * @return array|false {
    function image_hwstring( $width, $height ) { 
    188189 *     @type bool   $3 Whether the image is a resized image.
    189190 * }
    190191 */
    191 function image_downsize( $id, $size = 'medium' ) {
    192         $is_image = wp_attachment_is_image( $id );
     192function image_downsize( $attachment, $size = 'medium' ) {
     193
     194        $post = get_post( $attachment );
     195
     196        if ( ! $post || 'attachment' !== $post->post_type ) {
     197                return false;
     198        }
     199
     200        $is_image = wp_attachment_is_image( $post );
    193201
    194202        /**
    195203         * Filters whether to preempt the output of image_downsize().
    function image_downsize( $id, $size = 'medium' ) { 
    198206         * down-sizing the image, returning that value instead.
    199207         *
    200208         * @since 2.5.0
     209         * @since 5.6.0 add $post parameter.
    201210         *
    202211         * @param bool|array   $downsize Whether to short-circuit the image downsize.
    203212         * @param int          $id       Attachment ID for image.
    204213         * @param string|int[] $size     Requested image size. Can be any registered image size name, or
    205214         *                               an array of width and height values in pixels (in that order).
     215         * @param WP_Post      $post     Attachment post object.
    206216         */
    207         $out = apply_filters( 'image_downsize', false, $id, $size );
     217        $out = apply_filters( 'image_downsize', false, $post->ID, $size, $post );
    208218
    209219        if ( $out ) {
    210220                return $out;
    211221        }
    212222
    213         $img_url          = wp_get_attachment_url( $id );
    214         $meta             = wp_get_attachment_metadata( $id );
     223        $img_url          = wp_get_attachment_url( $post );
     224        $meta             = wp_get_attachment_metadata( $post );
    215225        $width            = 0;
    216226        $height           = 0;
    217227        $is_intermediate  = false;
    function image_downsize( $id, $size = 'medium' ) { 
    231241        }
    232242
    233243        // Try for a new style intermediate size.
    234         $intermediate = image_get_intermediate_size( $id, $size );
     244        $intermediate = image_get_intermediate_size( $post, $size );
    235245
    236246        if ( $intermediate ) {
    237247                $img_url         = str_replace( $img_url_basename, $intermediate['file'], $img_url );
    function image_downsize( $id, $size = 'medium' ) { 
    240250                $is_intermediate = true;
    241251        } elseif ( 'thumbnail' === $size ) {
    242252                // Fall back to the old thumbnail.
    243                 $thumb_file = wp_get_attachment_thumb_file( $id );
     253                $thumb_file = wp_get_attachment_thumb_file( $post );
    244254                $info       = null;
    245255
    246256                if ( $thumb_file ) {
    function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { 
    361371 * content.
    362372 *
    363373 * @since 2.5.0
     374 * @since 5.6.0 allow WP_Post object to be passed.
    364375 *
    365  * @param int          $id    Attachment ID.
     376 * @param int|WP_Post  $attachment Attachment post or post ID.
    366377 * @param string       $alt   Image description for the alt attribute.
    367378 * @param string       $title Image description for the title attribute.
    368379 * @param string       $align Part of the class name for aligning the image.
    function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { 
    370381 *                           width and height values in pixels (in that order). Default 'medium'.
    371382 * @return string HTML IMG element for given image attachment
    372383 */
    373 function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
     384function get_image_tag( $attachment, $alt, $title, $align, $size = 'medium' ) {
     385
     386        $post = get_post( $attachment );
    374387
     388        if ( ! $post || 'attachment' !== $post->post_type ) {
     389                return '';
     390        }
     391
     392        $id = $post->ID;
    375393        list( $img_src, $width, $height ) = image_downsize( $id, $size );
    376394        $hwstring                         = image_hwstring( $width, $height );
    377395
    function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) { 
    383401         * Filters the value of the attachment's image tag class attribute.
    384402         *
    385403         * @since 2.6.0
     404         * @since 5.6.0 add $post parameter.
    386405         *
    387406         * @param string       $class CSS class name or space-separated list of classes.
    388407         * @param int          $id    Attachment ID.
    389408         * @param string       $align Part of the class name for aligning the image.
    390409         * @param string|int[] $size  Requested image size. Can be any registered image size name, or
    391410         *                            an array of width and height values in pixels (in that order).
     411         * @param WP_Post      $post  Attachment post object.
    392412         */
    393         $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );
     413        $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size, $post );
    394414
    395415        $html = '<img src="' . esc_attr( $img_src ) . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
    396416
    function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) { 
    398418         * Filters the HTML content for the image tag.
    399419         *
    400420         * @since 2.6.0
     421         * @since 5.6.0 add $post parameter.
    401422         *
    402423         * @param string       $html  HTML content for the image.
    403424         * @param int          $id    Attachment ID.
    function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) { 
    406427         * @param string       $align Part of the class name for aligning the image.
    407428         * @param string|int[] $size  Requested image size. Can be any registered image size name, or
    408429         *                            an array of width and height values in pixels (in that order).
     430         * @param WP_Post      $post  Attachment post object.
    409431         */
    410         return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
     432        return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size, $post );
    411433}
    412434
    413435/**
    function wp_image_matches_ratio( $source_width, $source_height, $target_width, $ 
    740762 * browser scale down the image.
    741763 *
    742764 * @since 2.5.0
     765 * @since 5.6.0 allow WP_Post object to be passed.
    743766 *
    744  * @param int          $post_id Attachment ID.
    745  * @param string|int[] $size    Optional. Image size. Accepts any registered image size name, or an array
    746  *                              of width and height values in pixels (in that order). Default 'thumbnail'.
     767 * @param int|WP_Post  $attachment Attachment post or post ID.
     768 * @param string|int[] $size       Optional. Image size. Accepts any registered image size name, or an array
     769 *                                  of width and height values in pixels (in that order). Default 'thumbnail'.
    747770 * @return array|false {
    748771 *     Array of file relative path, width, and height on success. Additionally includes absolute
    749772 *     path and URL if registered size is passed to `$size` parameter. False on failure.
    function wp_image_matches_ratio( $source_width, $source_height, $target_width, $ 
    755778 *     @type string $url    URL of image.
    756779 * }
    757780 */
    758 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
    759         $imagedata = wp_get_attachment_metadata( $post_id );
     781function image_get_intermediate_size( $attachment, $size = 'thumbnail' ) {
    760782
    761         if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
     783        $post = get_post( $attachment );
     784        $imagedata = wp_get_attachment_metadata( $post );
     785
     786        if ( ! $size || ! $post || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
    762787                return false;
    763788        }
    764789
    function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 
    827852
    828853        // Include the full filesystem path of the intermediate file.
    829854        if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) {
    830                 $file_url     = wp_get_attachment_url( $post_id );
     855                $file_url     = wp_get_attachment_url( $post );
    831856                $data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] );
    832857                $data['url']  = path_join( dirname( $file_url ), $data['file'] );
    833858        }
    function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 
    836861         * Filters the output of image_get_intermediate_size()
    837862         *
    838863         * @since 4.4.0
     864         * @since 5.6.0 add $post parameter.
    839865         *
    840866         * @see image_get_intermediate_size()
    841867         *
    842868         * @param array        $data    Array of file relative path, width, and height on success. May also include
    843869         *                              file absolute path and URL.
    844          * @param int          $post_id The ID of the image attachment.
     870         * @param int                  The ID of the image attachment.
    845871         * @param string|int[] $size    Requested image size. Can be any registered image size name, or
    846872         *                              an array of width and height values in pixels (in that order).
     873         * @param WP_Post      $post    Attachment post object.
    847874         */
    848         return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
     875        return apply_filters( 'image_get_intermediate_size', $data, $post->ID, $size, $post );
    849876}
    850877
    851878/**
    function wp_get_registered_image_subsizes() { 
    933960 * Retrieves an image to represent an attachment.
    934961 *
    935962 * @since 2.5.0
     963 * @since 5.6.0 allow WP_Post object to be passed.
    936964 *
    937  * @param int          $attachment_id Image attachment ID.
     965 * @param int|WP_Post  $attachment    Attachment post or post ID.
    938966 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
    939967 *                                    width and height values in pixels (in that order). Default 'thumbnail'.
    940968 * @param bool         $icon          Optional. Whether the image should fall back to a mime type icon. Default false.
    function wp_get_registered_image_subsizes() { 
    947975 *     @type bool   $3 Whether the image is a resized image.
    948976 * }
    949977 */
    950 function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
     978function wp_get_attachment_image_src( $attachment, $size = 'thumbnail', $icon = false ) {
     979
     980        $post = get_post( $attachment );
     981
     982        if ( ! $post || 'attachment' !== $post->post_type ) {
     983                return false;
     984        }
     985
    951986        // Get a thumbnail or intermediate image if there is one.
     987        $attachment_id = $post->ID;
    952988        $image = image_downsize( $attachment_id, $size );
    953989        if ( ! $image ) {
    954990                $src = false;
    function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon 
    9731009         * Filters the attachment image source result.
    9741010         *
    9751011         * @since 4.3.0
     1012         * @since 5.6.0 add $post parameter.
    9761013         *
    9771014         * @param array|false  $image         {
    9781015         *     Array of image data, or boolean false if no image is available.
    function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon 
    9861023         * @param string|int[] $size          Requested image size. Can be any registered image size name, or
    9871024         *                                    an array of width and height values in pixels (in that order).
    9881025         * @param bool         $icon          Whether the image should be treated as an icon.
     1026         * @param WP_Post      $post          Attachment post object.
    9891027         */
    990         return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
     1028        return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon, $post );
    9911029}
    9921030
    9931031/**
    function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon 
    10011039 * @since 2.5.0
    10021040 * @since 4.4.0 The `$srcset` and `$sizes` attributes were added.
    10031041 * @since 5.5.0 The `$loading` attribute was added.
     1042 * @since 5.6.0 allow WP_Post object to be passed.
    10041043 *
    1005  * @param int          $attachment_id Image attachment ID.
     1044 * @param int|WP_Post  $attachment    Attachment post or post ID.
    10061045 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array
    10071046 *                                    of width and height values in pixels (in that order). Default 'thumbnail'.
    10081047 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
    function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon 
    10221061 * }
    10231062 * @return string HTML img element or empty string on failure.
    10241063 */
    1025 function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
     1064function wp_get_attachment_image( $attachment, $size = 'thumbnail', $icon = false, $attr = '' ) {
    10261065        $html  = '';
    1027         $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
     1066        $image = wp_get_attachment_image_src( $attachment, $size, $icon );
    10281067
    10291068        if ( $image ) {
    10301069                list( $src, $width, $height ) = $image;
    10311070
    1032                 $attachment = get_post( $attachment_id );
     1071                $post = get_post( $attachment );
    10331072                $hwstring   = image_hwstring( $width, $height );
    10341073                $size_class = $size;
    10351074
    10361075                if ( is_array( $size_class ) ) {
    1037                         $size_class = join( 'x', $size_class );
     1076                        $size_class = implode( 'x', $size_class );
    10381077                }
    10391078
    10401079                $default_attr = array(
    10411080                        'src'   => $src,
    10421081                        'class' => "attachment-$size_class size-$size_class",
    1043                         'alt'   => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
     1082                        'alt'   => trim( strip_tags( get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ) ),
    10441083                );
    10451084
    10461085                // Add `loading` attribute.
    function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f 
    10581097
    10591098                // Generate 'srcset' and 'sizes' if not already present.
    10601099                if ( empty( $attr['srcset'] ) ) {
    1061                         $image_meta = wp_get_attachment_metadata( $attachment_id );
     1100                        $image_meta = wp_get_attachment_metadata( $post );
    10621101
    10631102                        if ( is_array( $image_meta ) ) {
    10641103                                $size_array = array( absint( $width ), absint( $height ) );
    1065                                 $srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id );
    1066                                 $sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id );
     1104                                $srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $post->ID );
     1105                                $sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $post->ID );
    10671106
    10681107                                if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
    10691108                                        $attr['srcset'] = $srcset;
    function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f 
    10821121                 *
    10831122                 * @param array        $attr       Array of attribute values for the image markup, keyed by attribute name.
    10841123                 *                                 See wp_get_attachment_image().
    1085                  * @param WP_Post      $attachment Image attachment post.
     1124                 * @param WP_Post      $post      Image attachment post.
    10861125                 * @param string|int[] $size       Requested image size. Can be any registered image size name, or
    10871126                 *                                 an array of width and height values in pixels (in that order).
    10881127                 */
    1089                 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
     1128                $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $post, $size );
    10901129
    10911130                $attr = array_map( 'esc_attr', $attr );
    10921131                $html = rtrim( "<img $hwstring" );
    function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f 
    11041143/**
    11051144 * Get the URL of an image attachment.
    11061145 *
    1107  * @since 4.4.0
     1146 * @since 5.6.0 allow WP_Post object to be passed.
    11081147 *
    1109  * @param int          $attachment_id Image attachment ID.
     1148 * @param int|WP_Post  $attachment    Attachment post or post ID.
    11101149 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
    11111150 *                                    width and height values in pixels (in that order). Default 'thumbnail'.
    11121151 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
    11131152 * @return string|false Attachment URL or false if no image is available.
    11141153 */
    1115 function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
    1116         $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
     1154function wp_get_attachment_image_url( $attachment, $size = 'thumbnail', $icon = false ) {
     1155        $image = wp_get_attachment_image_src( $attachment, $size, $icon );
    11171156        return isset( $image['0'] ) ? $image['0'] : false;
    11181157}
    11191158
    function _wp_get_image_size_from_meta( $size_name, $image_meta ) { 
    11791218 * Retrieves the value for an image attachment's 'srcset' attribute.
    11801219 *
    11811220 * @since 4.4.0
     1221 * @since 5.6.0 allow WP_Post object to be passed.
    11821222 *
    11831223 * @see wp_calculate_image_srcset()
    11841224 *
    1185  * @param int          $attachment_id Image attachment ID.
     1225 * @param int|WP_Post  $attachment    Attachment post or post ID.
    11861226 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
    11871227 *                                    width and height values in pixels (in that order). Default 'medium'.
    11881228 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
    11891229 *                                    Default null.
    11901230 * @return string|bool A 'srcset' value string or false.
    11911231 */
    1192 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
    1193         $image = wp_get_attachment_image_src( $attachment_id, $size );
     1232function wp_get_attachment_image_srcset( $attachment, $size = 'medium', $image_meta = null ) {
     1233
     1234        $post = get_post( $attachment );
     1235
     1236        if ( ! $post || 'attachment' !== $post->post_type ) {
     1237                return false;
     1238        }
     1239
     1240        $image = wp_get_attachment_image_src( $post, $size );
    11941241
    11951242        if ( ! $image ) {
    11961243                return false;
    11971244        }
    11981245
    11991246        if ( ! is_array( $image_meta ) ) {
    1200                 $image_meta = wp_get_attachment_metadata( $attachment_id );
     1247                $image_meta = wp_get_attachment_metadata( $post );
    12011248        }
    12021249
    12031250        $image_src  = $image[0];
    function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $imag 
    12061253                absint( $image[2] ),
    12071254        );
    12081255
    1209         return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
     1256        return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $post->ID );
    12101257}
    12111258
    12121259/**
    function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac 
    14231470 *
    14241471 * @see wp_calculate_image_sizes()
    14251472 *
    1426  * @param int          $attachment_id Image attachment ID.
     1473 * @param int|WP_Post  $attachment    Attachment post or post ID.
    14271474 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
    14281475 *                                    width and height values in pixels (in that order). Default 'medium'.
    14291476 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
    14301477 *                                    Default null.
    14311478 * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
    14321479 */
    1433 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) {
    1434         $image = wp_get_attachment_image_src( $attachment_id, $size );
     1480function wp_get_attachment_image_sizes( $attachment, $size = 'medium', $image_meta = null ) {
     1481
     1482        $post = get_post( $attachment );
     1483
     1484        if ( ! $post || 'attachment' !== $post->post_type ) {
     1485                return false;
     1486        }
     1487
     1488        $image = wp_get_attachment_image_src( $post, $size );
    14351489
    14361490        if ( ! $image ) {
    14371491                return false;
    14381492        }
    14391493
    14401494        if ( ! is_array( $image_meta ) ) {
    1441                 $image_meta = wp_get_attachment_metadata( $attachment_id );
     1495                $image_meta = wp_get_attachment_metadata( $post );
    14421496        }
    14431497
    14441498        $image_src  = $image[0];
    function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image 
    14471501                absint( $image[2] ),
    14481502        );
    14491503
    1450         return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );
     1504        return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $post->ID );
    14511505}
    14521506
    14531507/**
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index 575a2fbaea..7cf9d10026 100644
    a b function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) { 
    59755975 * Retrieves attachment metadata for attachment ID.
    59765976 *
    59775977 * @since 2.1.0
     5978 * @since 5.6.0 allow WP_Post object to be passed.
     5979 *
     5980 * @param int|WP_Post   $attachment    Attachment post or post ID.
     5981 * @param bool          $unfiltered    Optional. If true, filters are not run. Default false.
    59785982 *
    5979  * @param int  $attachment_id Attachment post ID. Defaults to global $post.
    5980  * @param bool $unfiltered    Optional. If true, filters are not run. Default false.
    59815983 * @return array|false {
    59825984 *     Attachment metadata. False on failure.
    59835985 *
    function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) { 
    59895991 *     @type array  $image_meta Image metadata.
    59905992 * }
    59915993 */
    5992 function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
    5993         $attachment_id = (int) $attachment_id;
     5994function wp_get_attachment_metadata( $attachment, $unfiltered = false ) {
     5995        $post = get_post( $attachment );
    59945996
    5995         $data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
     5997        if ( ! $post || 'attachment' !== $post->post_type ) {
     5998                return false;
     5999        }
     6000
     6001        $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );
    59966002
    59976003        if ( empty( $data ) ) {
    59986004                return false;
    function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) { 
    60066012         * Filters the attachment meta data.
    60076013         *
    60086014         * @since 2.1.0
     6015         * @since 5.6.0 add $post parameter.
    60096016         *
    6010          * @param array|bool $data          Array of meta data for the given attachment, or false
     6017         * @param array|bool $data  Array of meta data for the given attachment, or false
    60116018         *                                  if the object does not exist.
    6012          * @param int        $attachment_id Attachment post ID.
     6019         * @param int               Attachment post ID.
     6020         * @param WP_Post    $post  Attachment WP_Post object.
    60136021         */
    6014         return apply_filters( 'wp_get_attachment_metadata', $data, $attachment_id );
     6022        return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID, $post );
    60156023}
    60166024
    60176025/**
    60186026 * Updates metadata for an attachment.
    60196027 *
    60206028 * @since 2.1.0
     6029 * @since 5.6.0 allow WP_Post object to be passed.
    60216030 *
    6022  * @param int   $attachment_id Attachment post ID.
    6023  * @param array $data          Attachment meta data.
     6031 * @param int|WP_Post  $attachment    Attachment post or post ID.
     6032 * @param array        $data          Attachment meta data.
    60246033 * @return int|bool False if $post is invalid.
    60256034 */
    6026 function wp_update_attachment_metadata( $attachment_id, $data ) {
    6027         $attachment_id = (int) $attachment_id;
     6035function wp_update_attachment_metadata( $attachment, $data ) {
    60286036
    6029         $post = get_post( $attachment_id );
    6030         if ( ! $post ) {
     6037        $post = get_post( $attachment );
     6038
     6039        if ( ! $post || 'attachment' !== $post->post_type ) {
    60316040                return false;
    60326041        }
    60336042
    function wp_update_attachment_metadata( $attachment_id, $data ) { 
    60356044         * Filters the updated attachment meta data.
    60366045         *
    60376046         * @since 2.1.0
     6047         * @since 5.6.0 add $post parameter.
    60386048         *
    6039          * @param array $data          Array of updated attachment meta data.
    6040          * @param int   $attachment_id Attachment post ID.
     6049         * @param array   $data          Array of updated attachment meta data.
     6050         * @param int     $attachment_id Attachment post ID.
     6051         * @param WP_Post $attachment    Attachment WP_Post object.
    60416052         */
    6042         $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
     6053        $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID, $post );
    60436054        if ( $data ) {
    60446055                return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
    6045         } else {
    6046                 return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
    60476056        }
     6057
     6058        return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
    60486059}
    60496060
    60506061/**
    60516062 * Retrieve the URL for an attachment.
    60526063 *
    60536064 * @since 2.1.0
     6065 * @since 5.6.0 allow WP_Post object to be passed.
    60546066 *
    60556067 * @global string $pagenow
    60566068 *
    6057  * @param int $attachment_id Optional. Attachment post ID. Defaults to global $post.
     6069 * @param int|WP_Post   $attachment    Attachment post or post ID.
     6070 *
    60586071 * @return string|false Attachment URL, otherwise false.
    60596072 */
    6060 function wp_get_attachment_url( $attachment_id = 0 ) {
    6061         $attachment_id = (int) $attachment_id;
     6073function wp_get_attachment_url( $attachment ) {
    60626074
    6063         $post = get_post( $attachment_id );
    6064         if ( ! $post ) {
    6065                 return false;
    6066         }
     6075        $post = get_post( $attachment );
    60676076
    6068         if ( 'attachment' !== $post->post_type ) {
     6077        if ( ! $post || 'attachment' !== $post->post_type ) {
    60696078                return false;
    60706079        }
    60716080
    function wp_get_attachment_url( $attachment_id = 0 ) { 
    61076116         * Filters the attachment URL.
    61086117         *
    61096118         * @since 2.1.0
     6119         * @since 5.6.0 add $post parameter.
    61106120         *
    6111          * @param string $url           URL for the given attachment.
    6112          * @param int    $attachment_id Attachment post ID.
     6121         * @param string  $url              URL for the given attachment.
     6122         * @param int     $attachment_id    Attachment post ID.
     6123         * @param WP_Post $post             Attachment WP_Post object.
    61136124         */
    6114         $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
     6125        $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID, $post );
    61156126
    61166127        if ( empty( $url ) ) {
    61176128                return false;
    function wp_get_attachment_url( $attachment_id = 0 ) { 
    61256136 *
    61266137 * @since 4.6.0
    61276138 *
    6128  * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
     6139 * @param int|WP_Post $attachment Attachment post or post ID.
     6140 *
    61296141 * @return string|false False on failure. Attachment caption on success.
    61306142 */
    6131 function wp_get_attachment_caption( $post_id = 0 ) {
    6132         $post_id = (int) $post_id;
    6133         $post    = get_post( $post_id );
    6134         if ( ! $post ) {
    6135                 return false;
    6136         }
     6143function wp_get_attachment_caption( $attachment ) {
    61376144
    6138         if ( 'attachment' !== $post->post_type ) {
     6145        $post = get_post( $attachment );
     6146
     6147        if ( ! $post || 'attachment' !== $post->post_type ) {
    61396148                return false;
    61406149        }
    61416150
    function wp_get_attachment_caption( $post_id = 0 ) { 
    61456154         * Filters the attachment caption.
    61466155         *
    61476156         * @since 4.6.0
     6157         * @since 5.6.0 add $post parameter.
    61486158         *
    61496159         * @param string $caption Caption for the given attachment.
    6150          * @param int    $post_id Attachment ID.
     6160         * @param int    $attachment_id Attachment ID.
     6161         * @param WP_Post $attachment Attachment WP_Post object.
    61516162         */
    6152         return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );
     6163        return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID, $post );
    61536164}
    61546165
    61556166/**
    61566167 * Retrieve thumbnail for an attachment.
    61576168 *
    61586169 * @since 2.1.0
     6170 * @since 5.6.0 allow WP_Post object to be passed.
     6171 *
     6172 * @param int|WP_Post $attachment Attachment post or post ID. Defaults to the global post.
    61596173 *
    6160  * @param int $post_id Optional. Attachment ID. Default 0.
    61616174 * @return string|false False on failure. Thumbnail file path on success.
    61626175 */
    6163 function wp_get_attachment_thumb_file( $post_id = 0 ) {
    6164         $post_id = (int) $post_id;
    6165         $post    = get_post( $post_id );
    6166         if ( ! $post ) {
     6176function wp_get_attachment_thumb_file( $attachment ) {
     6177
     6178        $post = get_post( $attachment );
     6179
     6180        if ( ! $post || 'attachment' !== $post->post_type ) {
    61676181                return false;
    61686182        }
    61696183
    function wp_get_attachment_thumb_file( $post_id = 0 ) { 
    61816195                         * Filters the attachment thumbnail file path.
    61826196                         *
    61836197                         * @since 2.1.0
     6198                         * @since 5.6.0 add $post parameter.
    61846199                         *
    6185                          * @param string $thumbfile File path to the attachment thumbnail.
    6186                          * @param int    $post_id   Attachment ID.
     6200                         * @param string  $thumbfile       File path to the attachment thumbnail.
     6201                         * @param int     $attachment_id   Attachment ID.
     6202                         * @param WP_Post $post            Attachment post object.
    61876203                         */
    6188                         return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     6204                        return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID, $post );
    61896205                }
    61906206        }
    61916207        return false;
    function wp_get_attachment_thumb_file( $post_id = 0 ) { 
    61956211 * Retrieve URL for an attachment thumbnail.
    61966212 *
    61976213 * @since 2.1.0
     6214 * @since 5.6.0 allow WP_Post object to be passed.
     6215 *
     6216 * @param int|WP_Post          $attachment    Attachment post or post ID.
    61986217 *
    6199  * @param int $post_id Optional. Attachment ID. Default 0.
    62006218 * @return string|false False on failure. Thumbnail URL on success.
    62016219 */
    6202 function wp_get_attachment_thumb_url( $post_id = 0 ) {
    6203         $post_id = (int) $post_id;
    6204         $post    = get_post( $post_id );
    6205         if ( ! $post ) {
     6220function wp_get_attachment_thumb_url( $attachment ) {
     6221
     6222        $post = get_post( $attachment );
     6223
     6224        if ( ! $post || 'attachment' !== $post->post_type ) {
    62066225                return false;
    62076226        }
    62086227
    function wp_get_attachment_thumb_url( $post_id = 0 ) { 
    62116230                return false;
    62126231        }
    62136232
    6214         $sized = image_downsize( $post_id, 'thumbnail' );
     6233        $sized = image_downsize( $post->ID, 'thumbnail' );
    62156234        if ( $sized ) {
    62166235                return $sized[0];
    62176236        }
    function wp_get_attachment_thumb_url( $post_id = 0 ) { 
    62276246         * Filters the attachment thumbnail URL.
    62286247         *
    62296248         * @since 2.1.0
     6249         * @since 5.6.0 add $post parameter.
    62306250         *
    6231          * @param string $url     URL for the attachment thumbnail.
    6232          * @param int    $post_id Attachment ID.
     6251         * @param string  $url              URL for the attachment thumbnail.
     6252         * @param int     $attachment_id    Attachment ID.
     6253         * @param WP_Post $post             Attachment post object.
    62336254         */
    6234         return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
     6255        return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID, $post );
    62356256}
    62366257
    62376258/**
    function wp_get_attachment_thumb_url( $post_id = 0 ) { 
    62446265 * @return bool True if one of the accepted types, false otherwise.
    62456266 */
    62466267function wp_attachment_is( $type, $post = null ) {
     6268
    62476269        $post = get_post( $post );
    6248         if ( ! $post ) {
     6270
     6271        if ( ! $post  || 'attachment' !== $post->post_type ) {
    62496272                return false;
    62506273        }
    62516274