Make WordPress Core

Ticket #37255: 37255-1.patch

File 37255-1.patch, 23.2 KB (added by Howdy_McGee, 6 years ago)

Attempt #2

  • 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        $post = get_post( $attachment );
     386       
     387        if( ! $post || 'attachment' !== $post->post_type ) {
     388                return '';
     389        }
     390       
     391        $id = $post->ID;
    377392        list( $img_src, $width, $height ) = image_downsize( $id, $size );
    378393        $hwstring                         = image_hwstring( $width, $height );
    379394
     
    391406         * @param string       $align Part of the class name for aligning the image.
    392407         * @param string|array $size  Size of image. Image size or array of width and height values (in that order).
    393408         *                            Default 'medium'.
     409         * @param WP_Post      $attachment Attachment post object.
    394410         */
    395         $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );
     411        $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size);
    396412
    397413        $html = '<img src="' . esc_attr( $img_src ) . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
    398414
     
    408424         * @param string       $align Part of the class name for aligning the image.
    409425         * @param string|array $size  Size of image. Image size or array of width and height values (in that order).
    410426         *                            Default 'medium'.
     427         * @param WP_Post      $attachment Attachment post object.
    411428         */
    412         return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
     429        return apply_filters( 'get_image_tag', $html, $post->ID, $alt, $title, $align, $size );
    413430}
    414431
    415432/**
     
    743760 *
    744761 * @since 2.5.0
    745762 *
    746  * @param int          $post_id Attachment ID.
     763 * @param int          $attachment Attachment post or post ID.
    747764 * @param array|string $size    Optional. Image size. Accepts any valid image size, or an array
    748765 *                              of width and height values in pixels (in that order).
    749766 *                              Default 'thumbnail'.
     
    758775 *     @type string $url    Image's URL.
    759776 * }
    760777 */
    761 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
    762         $imagedata = wp_get_attachment_metadata( $post_id );
     778function image_get_intermediate_size( $attachment, $size = 'thumbnail' ) {
     779       
     780        $post = get_post( $attachment );
     781        $imagedata = wp_get_attachment_metadata( $post );
    763782
    764         if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
     783        if ( ! $size || ! $post || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
    765784                return false;
    766785        }
    767786
     
    830849
    831850        // Include the full filesystem path of the intermediate file.
    832851        if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) {
    833                 $file_url     = wp_get_attachment_url( $post_id );
     852                $file_url     = wp_get_attachment_url( $post );
    834853                $data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] );
    835854                $data['url']  = path_join( dirname( $file_url ), $data['file'] );
    836855        }
     
    847866         * @param int          $post_id The post_id of the image attachment
    848867         * @param string|array $size    Registered image size or flat array of initially-requested height and width
    849868         *                              dimensions (in that order).
     869         * @param WP_Post      $attachment Attachment post object.
    850870         */
    851         return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
     871        return apply_filters( 'image_get_intermediate_size', $data, $post->ID, $size, $post );
    852872}
    853873
    854874/**
     
    937957 *
    938958 * @since 2.5.0
    939959 *
    940  * @param int          $attachment_id Image attachment ID.
     960 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    941961 * @param string|int[] $size          Optional. Image size. Accepts any valid image size name, or an array of width
    942962 *                                    and height values in pixels (in that order). Default 'thumbnail'.
    943963 * @param bool         $icon          Optional. Whether the image should fall back to a mime type icon. Default false.
     
    950970 *     @type bool   $3 Whether the image is a resized image.
    951971 * }
    952972 */
    953 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       
    954981        // Get a thumbnail or intermediate image if there is one.
     982        $attachment_id = $post->ID;
    955983        $image = image_downsize( $attachment_id, $size );
    956984        if ( ! $image ) {
    957985                $src = false;
     
    9891017         * @param string|int[] $size          Requested size of image. Image size name, or array of width
    9901018         *                                    and height values (in that order).
    9911019         * @param bool         $icon          Whether the image should be treated as an icon.
     1020         * @param WP_Post      $attachment    Attachment post object.
    9921021         */
    993         return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
     1022        return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon, $post );
    9941023}
    9951024
    9961025/**
     
    10031032 *
    10041033 * @since 2.5.0
    10051034 *
    1006  * @param int          $attachment_id Image attachment ID.
     1035 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    10071036 * @param string|array $size          Optional. Image size. Accepts any valid image size, or an array of width
    10081037 *                                    and height values in pixels (in that order). Default 'thumbnail'.
    10091038 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
     
    10201049 * }
    10211050 * @return string HTML img element or empty string on failure.
    10221051 */
    1023 function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
     1052function wp_get_attachment_image( $attachment, $size = 'thumbnail', $icon = false, $attr = '' ) {
    10241053        $html  = '';
    1025         $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
     1054        $image = wp_get_attachment_image_src( $attachment, $size, $icon );
    10261055
    10271056        if ( $image ) {
    10281057                list( $src, $width, $height ) = $image;
    10291058
    1030                 $attachment = get_post( $attachment_id );
     1059                $post = get_post( $attachment );
    10311060                $hwstring   = image_hwstring( $width, $height );
    10321061                $size_class = $size;
    10331062
     
    10381067                $default_attr = array(
    10391068                        'src'   => $src,
    10401069                        'class' => "attachment-$size_class size-$size_class",
    1041                         'alt'   => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
     1070                        'alt'   => trim( strip_tags( get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ) ),
    10421071                );
    10431072
    10441073                // Add `loading` attribute.
     
    10501079
    10511080                // Generate 'srcset' and 'sizes' if not already present.
    10521081                if ( empty( $attr['srcset'] ) ) {
    1053                         $image_meta = wp_get_attachment_metadata( $attachment_id );
     1082                        $image_meta = wp_get_attachment_metadata( $post );
    10541083
    10551084                        if ( is_array( $image_meta ) ) {
    10561085                                $size_array = array( absint( $width ), absint( $height ) );
    1057                                 $srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id );
    1058                                 $sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id );
     1086                                $srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $post->ID );
     1087                                $sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $post->ID );
    10591088
    10601089                                if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
    10611090                                        $attr['srcset'] = $srcset;
     
    10781107                 * @param string|array $size       Requested size. Image size or array of width and height values
    10791108                 *                                 (in that order). Default 'thumbnail'.
    10801109                 */
    1081                 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
     1110                $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $post, $size );
    10821111
    10831112                $attr = array_map( 'esc_attr', $attr );
    10841113                $html = rtrim( "<img $hwstring" );
     
    10981127 *
    10991128 * @since 4.4.0
    11001129 *
    1101  * @param int          $attachment_id Image attachment ID.
     1130 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    11021131 * @param string|array $size          Optional. Image size to retrieve. Accepts any valid image size, or an array
    11031132 *                                    of width and height values in pixels (in that order). Default 'thumbnail'.
    11041133 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
    11051134 * @return string|false Attachment URL or false if no image is available.
    11061135 */
    1107 function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
    1108         $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
     1136function wp_get_attachment_image_url( $attachment = null, $size = 'thumbnail', $icon = false ) {
     1137        $image = wp_get_attachment_image_src( $attachment, $size, $icon );
    11091138        return isset( $image['0'] ) ? $image['0'] : false;
    11101139}
    11111140
     
    11691198 *
    11701199 * @see wp_calculate_image_srcset()
    11711200 *
    1172  * @param int          $attachment_id Image attachment ID.
     1201 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    11731202 * @param array|string $size          Optional. Image size. Accepts any valid image size, or an array of
    11741203 *                                    width and height values in pixels (in that order). Default 'medium'.
    11751204 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
     
    11761205 *                                    Default null.
    11771206 * @return string|bool A 'srcset' value string or false.
    11781207 */
    1179 function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
    1180         $image = wp_get_attachment_image_src( $attachment_id, $size );
     1208function wp_get_attachment_image_srcset( $attachment = null, $size = 'medium', $image_meta = null ) {
     1209       
     1210        $post = get_post( $attachment );
     1211       
     1212        if ( ! $post || 'attachment' != $post->post_type ) {
     1213                return false;
     1214        }
     1215       
     1216        $image = wp_get_attachment_image_src( $post, $size );
    11811217
    11821218        if ( ! $image ) {
    11831219                return false;
     
    11841220        }
    11851221
    11861222        if ( ! is_array( $image_meta ) ) {
    1187                 $image_meta = wp_get_attachment_metadata( $attachment_id );
     1223                $image_meta = wp_get_attachment_metadata( $post );
    11881224        }
    11891225
    11901226        $image_src  = $image[0];
     
    11931229                absint( $image[2] ),
    11941230        );
    11951231
    1196         return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
     1232        return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $post->ID );
    11971233}
    11981234
    11991235/**
     
    14101446 *
    14111447 * @see wp_calculate_image_sizes()
    14121448 *
    1413  * @param int          $attachment_id Image attachment ID.
     1449 * @param int          $attachment    Attachment post or post ID. Defaults to global $post.
    14141450 * @param array|string $size          Optional. Image size. Accepts any valid image size, or an array of width
    14151451 *                                    and height values in pixels (in that order). Default 'medium'.
    14161452 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
     
    14171453 *                                    Default null.
    14181454 * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
    14191455 */
    1420 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) {
    1421         $image = wp_get_attachment_image_src( $attachment_id, $size );
     1456function wp_get_attachment_image_sizes( $attachment = null, $size = 'medium', $image_meta = null ) {
     1457       
     1458        $post = get_post( $attachment );
     1459       
     1460        if ( ! $post || 'attachment' != $post->post_type ) {
     1461                return false;
     1462        }
     1463       
     1464        $image = wp_get_attachment_image_src( $post, $size );
    14221465
    14231466        if ( ! $image ) {
    14241467                return false;
     
    14251468        }
    14261469
    14271470        if ( ! is_array( $image_meta ) ) {
    1428                 $image_meta = wp_get_attachment_metadata( $attachment_id );
     1471                $image_meta = wp_get_attachment_metadata( $post );
    14291472        }
    14301473
    14311474        $image_src  = $image[0];
     
    14341477                absint( $image[2] ),
    14351478        );
    14361479
    1437         return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );
     1480        return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $post->ID );
    14381481}
    14391482
    14401483/**
     
    46784721        add_image_size( '1536x1536', 1536, 1536 );
    46794722        // 2x large size.
    46804723        add_image_size( '2048x2048', 2048, 2048 );
    4681 }
     4724}
     4725 No newline at end of file
  • wp-includes/post.php

     
    59045904 *
    59055905 * @since 2.1.0
    59065906 *
    5907  * @param int  $attachment_id Attachment post ID. Defaults to global $post.
     5907 * @param int  $attachment    Attachment post or post ID. Defaults to global $post.
    59085908 * @param bool $unfiltered    Optional. If true, filters are not run. Default false.
    59095909 * @return array|false {
    59105910 *     Attachment metadata. False on failure.
     
    59175917 *     @type array  $image_meta Image metadata.
    59185918 * }
    59195919 */
    5920 function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
    5921         $attachment_id = (int) $attachment_id;
    5922 
    5923         $post = get_post( $attachment_id );
    5924         if ( ! $post ) {
     5920function wp_get_attachment_metadata( $attachment = null, $unfiltered = false ) {
     5921       
     5922        $post = get_post( $attachment );
     5923       
     5924        if ( ! $post || 'attachment' !== $post->post_type ) {
    59255925                return false;
    59265926        }
    59275927
     
    59395939         * @param array|bool $data          Array of meta data for the given attachment, or false
    59405940         *                                  if the object does not exist.
    59415941         * @param int        $attachment_id Attachment post ID.
     5942         * @param WP_Post    $attachment Attachment WP_Post object.
    59425943         */
    5943         return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );
     5944        return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID, $post );
    59445945}
    59455946
    59465947/**
     
    59485949 *
    59495950 * @since 2.1.0
    59505951 *
    5951  * @param int   $attachment_id Attachment post ID.
     5952 * @param int   $attachment    Attachment post or post ID.
    59525953 * @param array $data          Attachment meta data.
    59535954 * @return int|bool False if $post is invalid.
    59545955 */
    5955 function wp_update_attachment_metadata( $attachment_id, $data ) {
    5956         $attachment_id = (int) $attachment_id;
     5956function wp_update_attachment_metadata( $attachment, $data ) {
    59575957
    5958         $post = get_post( $attachment_id );
    5959         if ( ! $post ) {
     5958        $post = get_post( $attachment );
     5959       
     5960        if ( ! $post || 'attachment' !== $post->post_type ) {
    59605961                return false;
    59615962        }
    59625963
     
    59675968         *
    59685969         * @param array $data          Array of updated attachment meta data.
    59695970         * @param int   $attachment_id Attachment post ID.
     5971         * @param WP_Post $attachment Attachment WP_Post object.
    59705972         */
    5971         $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
     5973        $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID, $post );
    59725974        if ( $data ) {
    59735975                return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
    59745976        } else {
     
    59835985 *
    59845986 * @global string $pagenow
    59855987 *
    5986  * @param int $attachment_id Optional. Attachment post ID. Defaults to global $post.
     5988 * @param int $attachment Optional. Attachment post or post ID. Defaults to global $post.
    59875989 * @return string|false Attachment URL, otherwise false.
    59885990 */
    5989 function wp_get_attachment_url( $attachment_id = 0 ) {
    5990         $attachment_id = (int) $attachment_id;
     5991function wp_get_attachment_url( $attachment = null ) {
    59915992
    5992         $post = get_post( $attachment_id );
    5993         if ( ! $post ) {
     5993        $post = get_post( $attachment );
     5994       
     5995        if ( ! $post || 'attachment' !== $post->post_type ) {
    59945996                return false;
    59955997        }
    59965998
    5997         if ( 'attachment' !== $post->post_type ) {
    5998                 return false;
    5999         }
    6000 
    60015999        $url = '';
    60026000        // Get attached file.
    60036001        $file = get_post_meta( $post->ID, '_wp_attached_file', true );
     
    60396037         *
    60406038         * @param string $url           URL for the given attachment.
    60416039         * @param int    $attachment_id Attachment post ID.
     6040         * @param WP_Post $attachment Attachment WP_Post object.
    60426041         */
    6043         $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
     6042        $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID, $post );
    60446043
    60456044        if ( empty( $url ) ) {
    60466045                return false;
     
    60546053 *
    60556054 * @since 4.6.0
    60566055 *
    6057  * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
     6056 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global $post.
    60586057 * @return string|false False on failure. Attachment caption on success.
    60596058 */
    6060 function wp_get_attachment_caption( $post_id = 0 ) {
    6061         $post_id = (int) $post_id;
    6062         $post    = get_post( $post_id );
    6063         if ( ! $post ) {
     6059function wp_get_attachment_caption( $attachment = null ) {
     6060       
     6061        $post = get_post( $attachment );
     6062       
     6063        if ( ! $post || 'attachment' !== $post->post_type ) {
    60646064                return false;
    60656065        }
    60666066
    6067         if ( 'attachment' !== $post->post_type ) {
    6068                 return false;
    6069         }
    6070 
    60716067        $caption = $post->post_excerpt;
    60726068
    60736069        /**
     
    60766072         * @since 4.6.0
    60776073         *
    60786074         * @param string $caption Caption for the given attachment.
    6079          * @param int    $post_id Attachment ID.
     6075         * @param int    $attachment_id Attachment ID.
     6076         * @param WP_Post $attachment Attachment WP_Post object.
    60806077         */
    6081         return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );
     6078        return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID, $post );
    60826079}
    60836080
    60846081/**
     
    60866083 *
    60876084 * @since 2.1.0
    60886085 *
    6089  * @param int $post_id Optional. Attachment ID. Default 0.
     6086 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global post.
    60906087 * @return string|false False on failure. Thumbnail file path on success.
    60916088 */
    6092 function wp_get_attachment_thumb_file( $post_id = 0 ) {
    6093         $post_id = (int) $post_id;
    6094         $post    = get_post( $post_id );
    6095         if ( ! $post ) {
     6089function wp_get_attachment_thumb_file( $attachment = null ) {
     6090       
     6091        $post = get_post( $attachment );
     6092       
     6093        if ( ! $post || 'attachment' != $post->post_type ) {
    60966094                return false;
    60976095        }
    60986096
     
    61006098        if ( ! is_array( $imagedata ) ) {
    61016099                return false;
    61026100        }
    6103 
     6101       
    61046102        $file = get_attached_file( $post->ID );
    6105 
     6103       
    61066104        if ( ! empty( $imagedata['thumb'] ) ) {
    61076105                $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
    61086106                if ( file_exists( $thumbfile ) ) {
     
    61116109                         *
    61126110                         * @since 2.1.0
    61136111                         *
    6114                          * @param string $thumbfile File path to the attachment thumbnail.
    6115                          * @param int    $post_id   Attachment ID.
     6112                         * @param string $thumbfile       File path to the attachment thumbnail.
     6113                         * @param int    $attachment_id   Attachment ID.
     6114                         * @param WP_Post $attachment     Attachment post object.
    61166115                         */
    6117                         return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     6116                        return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID, $post );
    61186117                }
    61196118        }
    61206119        return false;
     
    61256124 *
    61266125 * @since 2.1.0
    61276126 *
    6128  * @param int $post_id Optional. Attachment ID. Default 0.
     6127 * @param int|WP_Post $attachment Optional. Attachment post or post ID. Defaults to the global post.
    61296128 * @return string|false False on failure. Thumbnail URL on success.
    61306129 */
    6131 function wp_get_attachment_thumb_url( $post_id = 0 ) {
    6132         $post_id = (int) $post_id;
    6133         $post    = get_post( $post_id );
    6134         if ( ! $post ) {
     6130function wp_get_attachment_thumb_url( $attachment = null ) {
     6131       
     6132        $post = get_post( $attachment );
     6133       
     6134        if ( ! $post || 'attachment' != $post->post_type ) {
    61356135                return false;
    61366136        }
    61376137
     
    61406140                return false;
    61416141        }
    61426142
    6143         $sized = image_downsize( $post_id, 'thumbnail' );
     6143        $sized = image_downsize( $post->ID, 'thumbnail' );
    61446144        if ( $sized ) {
    61456145                return $sized[0];
    61466146        }
     
    61586158         * @since 2.1.0
    61596159         *
    61606160         * @param string $url     URL for the attachment thumbnail.
    6161          * @param int    $post_id Attachment ID.
     6161         * @param int    $attachment_id Attachment ID.
     6162         * @param WP_Post $attachment Attachment post object.
    61626163         */
    6163         return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
     6164        return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID, $post );
    61646165}
    61656166
    61666167/**
     
    61736174 * @return bool True if one of the accepted types, false otherwise.
    61746175 */
    61756176function wp_attachment_is( $type, $post = null ) {
     6177       
    61766178        $post = get_post( $post );
    6177         if ( ! $post ) {
     6179       
     6180        if ( ! $post  || 'attachment' != $post->post_type ) {
    61786181                return false;
    61796182        }
    61806183
     
    74157418         * @param int    $attachment_id      Attachment ID.
    74167419         */
    74177420        return apply_filters( 'wp_get_original_image_url', $original_image_url, $attachment_id );
    7418 }
     7421}
     7422 No newline at end of file