Make WordPress Core

Ticket #37255: 37255.diff

File 37255.diff, 23.3 KB (added by Howdy_McGee, 6 years ago)

Updated attachment functions to allow post objects.

  • wp-includes/media.php

     
    176176 *
    177177 * @since 2.5.0
    178178 *
    179  * @param int          $id   Attachment ID for image.
     179 * @param int          $attachment   Attachment post or attachment ID for image. Defaults to global $post.
    180180 * @param string|int[] $size Optional. Image size to scale to. Accepts any valid image size name,
    181181 *                           or an array of width and height values in pixels (in that order).
    182182 *                           Default 'medium'.
     
    189189 *     @type bool   $3 Whether the image is a resized image.
    190190 * }
    191191 */
    192 function image_downsize( $id, $size = 'medium' ) {
    193         $is_image = wp_attachment_is_image( $id );
     192function image_downsize( $attachment = null, $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 );
    194201
    195202        /**
    196203         * Filters whether to preempt the output of image_downsize().
     
    204211         * @param int          $id       Attachment ID for image.
    205212         * @param array|string $size     Requested size of image. Image size name, or array of width
    206213         *                               and height values (in that order).
     214         * @param WP_Post      $attachment Attachment post object.
    207215         */
    208         $out = apply_filters( 'image_downsize', false, $id, $size );
     216        $out = apply_filters( 'image_downsize', false, $post->ID, $size, $post );
    209217
    210218        if ( $out ) {
    211219                return $out;
    212220        }
    213221
    214         $img_url          = wp_get_attachment_url( $id );
    215         $meta             = wp_get_attachment_metadata( $id );
     222        $img_url          = wp_get_attachment_url( $post );
     223        $meta             = wp_get_attachment_metadata( $post );
    216224        $width            = 0;
    217225        $height           = 0;
    218226        $is_intermediate  = false;
     
    232240        }
    233241
    234242        // Try for a new style intermediate size.
    235         $intermediate = image_get_intermediate_size( $id, $size );
     243        $intermediate = image_get_intermediate_size( $post, $size );
    236244
    237245        if ( $intermediate ) {
    238246                $img_url         = str_replace( $img_url_basename, $intermediate['file'], $img_url );
     
    241249                $is_intermediate = true;
    242250        } elseif ( 'thumbnail' === $size ) {
    243251                // Fall back to the old thumbnail.
    244                 $thumb_file = wp_get_attachment_thumb_file( $id );
     252                $thumb_file = wp_get_attachment_thumb_file( $post );
    245253                $info       = null;
    246254
    247255                if ( $thumb_file ) {
     
    363371 *
    364372 * @since 2.5.0
    365373 *
    366  * @param int          $id    Attachment ID.
     374 * @param int          $attachment Attachment post or post ID.
    367375 * @param string       $alt   Image description for the alt attribute.
    368376 * @param string       $title Image description for the title attribute.
    369377 * @param string       $align Part of the class name for aligning the image.
     
    372380 *                            (in that order). Default 'medium'.
    373381 * @return string HTML IMG element for given image attachment
    374382 */
    375 function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
    376 
     383function get_image_tag( $attachment, $alt, $title, $align, $size = 'medium' ) {
     384       
     385        if( $attachment instanceof WP_Post && 'attachment' == $attachment->post_type ) {
     386                $id = $attachment->ID;
     387        } else if( is_numeric( $attachment ) ) {
     388                $id = $attachment;
     389        } else {
     390                return '';
     391        }
     392       
    377393        list( $img_src, $width, $height ) = image_downsize( $id, $size );
    378394        $hwstring                         = image_hwstring( $width, $height );
    379395
     
    391407         * @param string       $align Part of the class name for aligning the image.
    392408         * @param string|array $size  Size of image. Image size or array of width and height values (in that order).
    393409         *                            Default 'medium'.
     410         * @param WP_Post      $attachment Attachment post object.
    394411         */
    395         $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );
     412        $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size);
    396413
    397414        $html = '<img src="' . esc_attr( $img_src ) . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
    398415
     
    408425         * @param string       $align Part of the class name for aligning the image.
    409426         * @param string|array $size  Size of image. Image size or array of width and height values (in that order).
    410427         *                            Default 'medium'.
     428         * @param WP_Post      $attachment Attachment post object.
    411429         */
    412430        return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
    413431}
     
    743761 *
    744762 * @since 2.5.0
    745763 *
    746  * @param int          $post_id Attachment ID.
     764 * @param int          $attachment Attachment post or post ID.
    747765 * @param array|string $size    Optional. Image size. Accepts any valid image size, or an array
    748766 *                              of width and height values in pixels (in that order).
    749767 *                              Default 'thumbnail'.
     
    758776 *     @type string $url    Image's URL.
    759777 * }
    760778 */
    761 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
    762         $imagedata = wp_get_attachment_metadata( $post_id );
     779function image_get_intermediate_size( $attachment, $size = 'thumbnail' ) {
     780       
     781        $post = get_post( $attachment );
     782        $imagedata = wp_get_attachment_metadata( $post );
    763783
    764         if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
     784        if ( ! $size || ! $post || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
    765785                return false;
    766786        }
    767787
     
    830850
    831851        // Include the full filesystem path of the intermediate file.
    832852        if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) {
    833                 $file_url     = wp_get_attachment_url( $post_id );
     853                $file_url     = wp_get_attachment_url( $post );
    834854                $data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] );
    835855                $data['url']  = path_join( dirname( $file_url ), $data['file'] );
    836856        }
     
    847867         * @param int          $post_id The post_id of the image attachment
    848868         * @param string|array $size    Registered image size or flat array of initially-requested height and width
    849869         *                              dimensions (in that order).
     870         * @param WP_Post      $attachment Attachment post object.
    850871         */
    851         return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
     872        return apply_filters( 'image_get_intermediate_size', $data, $post->ID, $size, $post );
    852873}
    853874
    854875/**
     
    937958 *
    938959 * @since 2.5.0
    939960 *
    940  * @param int          $attachment_id Image attachment ID.
     961 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    941962 * @param string|int[] $size          Optional. Image size. Accepts any valid image size name, or an array of width
    942963 *                                    and height values in pixels (in that order). Default 'thumbnail'.
    943964 * @param bool         $icon          Optional. Whether the image should fall back to a mime type icon. Default false.
     
    949970 *     @type int    $2 Image height in pixels.
    950971 * }
    951972 */
    952 function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
     973function wp_get_attachment_image_src( $attachment = null, $size = 'thumbnail', $icon = false ) {
     974       
     975        $post = get_post( $attachment );
     976       
     977        if ( ! $post || 'attachment' != $post->post_type ) {
     978                return false;
     979        }
     980       
    953981        // Get a thumbnail or intermediate image if there is one.
     982        $attachment_id = $post->ID;
    954983        $image = image_downsize( $attachment_id, $size );
    955984        if ( ! $image ) {
    956985                $src = false;
     
    9871016         * @param string|int[] $size          Requested size of image. Image size name, or array of width
    9881017         *                                    and height values (in that order).
    9891018         * @param bool         $icon          Whether the image should be treated as an icon.
     1019         * @param WP_Post      $attachment    Attachment post object.
    9901020         */
    991         return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
     1021        return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon, $post );
    9921022}
    9931023
    9941024/**
     
    10011031 *
    10021032 * @since 2.5.0
    10031033 *
    1004  * @param int          $attachment_id Image attachment ID.
     1034 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    10051035 * @param string|array $size          Optional. Image size. Accepts any valid image size, or an array of width
    10061036 *                                    and height values in pixels (in that order). Default 'thumbnail'.
    10071037 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
     
    10181048 * }
    10191049 * @return string HTML img element or empty string on failure.
    10201050 */
    1021 function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
     1051function wp_get_attachment_image( $attachment = null, $size = 'thumbnail', $icon = false, $attr = '' ) {
     1052       
     1053        $post = get_post( $attachment );
     1054       
     1055        if ( ! $post || 'attachment' != $post->post_type ) {
     1056                return '';
     1057        }
     1058       
    10221059        $html  = '';
    1023         $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
     1060        $image = wp_get_attachment_image_src( $post, $size, $icon );
    10241061        if ( $image ) {
    10251062                list( $src, $width, $height ) = $image;
    10261063                $hwstring                     = image_hwstring( $width, $height );
     
    10281065                if ( is_array( $size_class ) ) {
    10291066                        $size_class = join( 'x', $size_class );
    10301067                }
    1031                 $attachment   = get_post( $attachment_id );
    10321068                $default_attr = array(
    10331069                        'src'   => $src,
    10341070                        'class' => "attachment-$size_class size-$size_class",
    1035                         'alt'   => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
     1071                        'alt'   => trim( strip_tags( get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ) ),
    10361072                );
    10371073
    10381074                $attr = wp_parse_args( $attr, $default_attr );
     
    10391075
    10401076                // Generate 'srcset' and 'sizes' if not already present.
    10411077                if ( empty( $attr['srcset'] ) ) {
    1042                         $image_meta = wp_get_attachment_metadata( $attachment_id );
     1078                        $image_meta = wp_get_attachment_metadata( $post );
    10431079
    10441080                        if ( is_array( $image_meta ) ) {
    10451081                                $size_array = array( absint( $width ), absint( $height ) );
    1046                                 $srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id );
    1047                                 $sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id );
     1082                                $srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $post->ID );
     1083                                $sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $post->ID );
    10481084
    10491085                                if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
    10501086                                        $attr['srcset'] = $srcset;
     
    10671103                 * @param string|array $size       Requested size. Image size or array of width and height values
    10681104                 *                                 (in that order). Default 'thumbnail'.
    10691105                 */
    1070                 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
     1106                $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $post, $size );
    10711107                $attr = array_map( 'esc_attr', $attr );
    10721108                $html = rtrim( "<img $hwstring" );
    10731109                foreach ( $attr as $name => $value ) {
     
    10841120 *
    10851121 * @since 4.4.0
    10861122 *
    1087  * @param int          $attachment_id Image attachment ID.
     1123 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    10881124 * @param string|array $size          Optional. Image size to retrieve. Accepts any valid image size, or an array
    10891125 *                                    of width and height values in pixels (in that order). Default 'thumbnail'.
    10901126 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
    10911127 * @return string|false Attachment URL or false if no image is available.
    10921128 */
    1093 function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
    1094         $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
     1129function wp_get_attachment_image_url( $attachment = null, $size = 'thumbnail', $icon = false ) {
     1130        $image = wp_get_attachment_image_src( $attachment, $size, $icon );
    10951131        return isset( $image['0'] ) ? $image['0'] : false;
    10961132}
    10971133
     
    11551191 *
    11561192 * @see wp_calculate_image_srcset()
    11571193 *
    1158  * @param int          $attachment_id Image attachment ID.
     1194 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    11591195 * @param array|string $size          Optional. Image size. Accepts any valid image size, or an array of
    11601196 *                                    width and height values in pixels (in that order). Default 'medium'.
    11611197 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
     
    11621198 *                                    Default null.
    11631199 * @return string|bool A 'srcset' value string or false.
    11641200 */
    1165 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
    1166         $image = wp_get_attachment_image_src( $attachment_id, $size );
     1201function wp_get_attachment_image_srcset( $attachment = null, $size = 'medium', $image_meta = null ) {
     1202       
     1203        $post = get_post( $attachment );
     1204       
     1205        if ( ! $post || 'attachment' != $post->post_type ) {
     1206                return false;
     1207        }
     1208       
     1209        $image = wp_get_attachment_image_src( $post, $size );
    11671210
    11681211        if ( ! $image ) {
    11691212                return false;
     
    11701213        }
    11711214
    11721215        if ( ! is_array( $image_meta ) ) {
    1173                 $image_meta = wp_get_attachment_metadata( $attachment_id );
     1216                $image_meta = wp_get_attachment_metadata( $post );
    11741217        }
    11751218
    11761219        $image_src  = $image[0];
     
    11791222                absint( $image[2] ),
    11801223        );
    11811224
    1182         return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
     1225        return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $post->ID );
    11831226}
    11841227
    11851228/**
     
    13961439 *
    13971440 * @see wp_calculate_image_sizes()
    13981441 *
    1399  * @param int          $attachment_id Image attachment ID.
     1442 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    14001443 * @param array|string $size          Optional. Image size. Accepts any valid image size, or an array of width
    14011444 *                                    and height values in pixels (in that order). Default 'medium'.
    14021445 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
     
    14031446 *                                    Default null.
    14041447 * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
    14051448 */
    1406 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) {
    1407         $image = wp_get_attachment_image_src( $attachment_id, $size );
     1449function wp_get_attachment_image_sizes( $attachment = null, $size = 'medium', $image_meta = null ) {
     1450       
     1451        $post = get_post( $attachment );
     1452       
     1453        if ( ! $post || 'attachment' != $post->post_type ) {
     1454                return false;
     1455        }
     1456       
     1457        $image = wp_get_attachment_image_src( $post, $size );
    14081458
    14091459        if ( ! $image ) {
    14101460                return false;
     
    14111461        }
    14121462
    14131463        if ( ! is_array( $image_meta ) ) {
    1414                 $image_meta = wp_get_attachment_metadata( $attachment_id );
     1464                $image_meta = wp_get_attachment_metadata( $post );
    14151465        }
    14161466
    14171467        $image_src  = $image[0];
     
    14201470                absint( $image[2] ),
    14211471        );
    14221472
    1423         return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );
     1473        return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $post->ID );
    14241474}
    14251475
    14261476/**
     
    44734523        add_image_size( '1536x1536', 1536, 1536 );
    44744524        // 2x large size.
    44754525        add_image_size( '2048x2048', 2048, 2048 );
    4476 }
     4526}
     4527 No newline at end of file
  • wp-includes/post.php

     
    57705770 *
    57715771 * @since 2.1.0
    57725772 *
    5773  * @param int  $attachment_id Attachment post ID. Defaults to global $post.
     5773 * @param int|WP_Post  $attachment Attachment post or post ID. Defaults to global $post.
    57745774 * @param bool $unfiltered    Optional. If true, filters are not run. Default false.
    57755775 * @return mixed Attachment meta field. False on failure.
    57765776 */
    5777 function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
    5778         $attachment_id = (int) $attachment_id;
    5779         $post          = get_post( $attachment_id );
    5780         if ( ! $post ) {
     5777function wp_get_attachment_metadata( $attachment = null, $unfiltered = false ) {
     5778
     5779        $post = get_post( $attachment );
     5780       
     5781        if ( ! $post || 'attachment' != $post->post_type ) {
    57815782                return false;
    57825783        }
    57835784
     
    57955796         * @param array|bool $data          Array of meta data for the given attachment, or false
    57965797         *                                  if the object does not exist.
    57975798         * @param int        $attachment_id Attachment post ID.
     5799         * @param WP_Post    $attachment Attachment WP_Post object.
    57985800         */
    5799         return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );
     5801        return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID, $post );
    58005802}
    58015803
    58025804/**
     
    58045806 *
    58055807 * @since 2.1.0
    58065808 *
    5807  * @param int   $attachment_id Attachment post ID.
     5809 * @param int|WP_Post   $attachment Attachment post or post ID.
    58085810 * @param array $data          Attachment meta data.
    58095811 * @return int|bool False if $post is invalid.
    58105812 */
    5811 function wp_update_attachment_metadata( $attachment_id, $data ) {
    5812         $attachment_id = (int) $attachment_id;
    5813         $post          = get_post( $attachment_id );
    5814         if ( ! $post ) {
     5813function wp_update_attachment_metadata( $attachment, $data ) {
     5814       
     5815        $post = get_post( $attachment );
     5816       
     5817        if ( ! $post || 'attachment' != $post->post_type ) {
    58155818                return false;
    58165819        }
    58175820
     
    58225825         *
    58235826         * @param array $data          Array of updated attachment meta data.
    58245827         * @param int   $attachment_id Attachment post ID.
     5828         * @param WP_Post $attachment Attachment WP_Post object.
    58255829         */
    5826         $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
     5830        $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID, $post );
    58275831        if ( $data ) {
    58285832                return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
    58295833        } else {
     
    58385842 *
    58395843 * @global string $pagenow
    58405844 *
    5841  * @param int $attachment_id Optional. Attachment post ID. Defaults to global $post.
     5845 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global $post.
    58425846 * @return string|false Attachment URL, otherwise false.
    58435847 */
    5844 function wp_get_attachment_url( $attachment_id = 0 ) {
    5845         $attachment_id = (int) $attachment_id;
    5846         $post          = get_post( $attachment_id );
    5847         if ( ! $post ) {
     5848function wp_get_attachment_url( $attachment = null ) {
     5849       
     5850        $post = get_post( $attachment );
     5851       
     5852        if ( ! $post || 'attachment' != $post->post_type ) {
    58485853                return false;
    58495854        }
    58505855
    5851         if ( 'attachment' != $post->post_type ) {
    5852                 return false;
    5853         }
    5854 
    58555856        $url = '';
    58565857        // Get attached file.
    58575858        $file = get_post_meta( $post->ID, '_wp_attached_file', true );
     
    58935894         *
    58945895         * @param string $url           URL for the given attachment.
    58955896         * @param int    $attachment_id Attachment post ID.
     5897         * @param WP_Post $attachment Attachment WP_Post object.
    58965898         */
    5897         $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
     5899        $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID, $post );
    58985900
    58995901        if ( empty( $url ) ) {
    59005902                return false;
     
    59085910 *
    59095911 * @since 4.6.0
    59105912 *
    5911  * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
     5913 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global $post.
    59125914 * @return string|false False on failure. Attachment caption on success.
    59135915 */
    5914 function wp_get_attachment_caption( $post_id = 0 ) {
    5915         $post_id = (int) $post_id;
    5916         $post    = get_post( $post_id );
    5917         if ( ! $post ) {
     5916function wp_get_attachment_caption( $attachment = null ) {
     5917       
     5918        $post = get_post( $attachment );
     5919       
     5920        if ( ! $post || 'attachment' !== $post->post_type ) {
    59185921                return false;
    59195922        }
    59205923
    5921         if ( 'attachment' !== $post->post_type ) {
    5922                 return false;
    5923         }
    5924 
    59255924        $caption = $post->post_excerpt;
    59265925
    59275926        /**
     
    59305929         * @since 4.6.0
    59315930         *
    59325931         * @param string $caption Caption for the given attachment.
    5933          * @param int    $post_id Attachment ID.
     5932         * @param int    $attachment_id Attachment ID.
     5933         * @param WP_Post $attachment Attachment WP_Post object.
    59345934         */
    5935         return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );
     5935        return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID, $post );
    59365936}
    59375937
    59385938/**
     
    59405940 *
    59415941 * @since 2.1.0
    59425942 *
    5943  * @param int $post_id Optional. Attachment ID. Default 0.
     5943 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global post.
    59445944 * @return string|false False on failure. Thumbnail file path on success.
    59455945 */
    5946 function wp_get_attachment_thumb_file( $post_id = 0 ) {
    5947         $post_id = (int) $post_id;
    5948         $post    = get_post( $post_id );
    5949         if ( ! $post ) {
     5946function wp_get_attachment_thumb_file( $attachment = null ) {
     5947       
     5948        $post = get_post( $attachment );
     5949       
     5950        if ( ! $post || 'attachment' != $post->post_type ) {
    59505951                return false;
    59515952        }
    59525953
     
    59545955        if ( ! is_array( $imagedata ) ) {
    59555956                return false;
    59565957        }
    5957 
     5958       
    59585959        $file = get_attached_file( $post->ID );
    5959 
     5960       
    59605961        if ( ! empty( $imagedata['thumb'] ) ) {
    59615962                $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
    59625963                if ( file_exists( $thumbfile ) ) {
     
    59655966                         *
    59665967                         * @since 2.1.0
    59675968                         *
    5968                          * @param string $thumbfile File path to the attachment thumbnail.
    5969                          * @param int    $post_id   Attachment ID.
     5969                         * @param string $thumbfile       File path to the attachment thumbnail.
     5970                         * @param int    $attachment_id   Attachment ID.
     5971                         * @param WP_Post $attachment     Attachment post object.
    59705972                         */
    5971                         return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     5973                        return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID, $post );
    59725974                }
    59735975        }
    59745976        return false;
     
    59795981 *
    59805982 * @since 2.1.0
    59815983 *
    5982  * @param int $post_id Optional. Attachment ID. Default 0.
     5984 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global post.
    59835985 * @return string|false False on failure. Thumbnail URL on success.
    59845986 */
    5985 function wp_get_attachment_thumb_url( $post_id = 0 ) {
    5986         $post_id = (int) $post_id;
    5987         $post    = get_post( $post_id );
    5988         if ( ! $post ) {
     5987function wp_get_attachment_thumb_url( $attachment = null ) {
     5988       
     5989        $post = get_post( $attachment );
     5990       
     5991        if ( ! $post || 'attachment' != $post->post_type ) {
    59895992                return false;
    59905993        }
    59915994
     
    59945997                return false;
    59955998        }
    59965999
    5997         $sized = image_downsize( $post_id, 'thumbnail' );
     6000        $sized = image_downsize( $post->ID, 'thumbnail' );
    59986001        if ( $sized ) {
    59996002                return $sized[0];
    60006003        }
     
    60126015         * @since 2.1.0
    60136016         *
    60146017         * @param string $url     URL for the attachment thumbnail.
    6015          * @param int    $post_id Attachment ID.
     6018         * @param int    $attachment_id Attachment ID.
     6019         * @param WP_Post $attachment Attachment post object.
    60166020         */
    6017         return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
     6021        return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID, $post );
    60186022}
    60196023
    60206024/**
     
    60276031 * @return bool True if one of the accepted types, false otherwise.
    60286032 */
    60296033function wp_attachment_is( $type, $post = null ) {
     6034       
    60306035        $post = get_post( $post );
    6031         if ( ! $post ) {
     6036       
     6037        if ( ! $post  || 'attachment' != $post->post_type ) {
    60326038                return false;
    60336039        }
    60346040
     
    72637269         * @param int    $attachment_id      Attachment ID.
    72647270         */
    72657271        return apply_filters( 'wp_get_original_image_url', $original_image_url, $attachment_id );
    7266 }
     7272}
     7273 No newline at end of file