Make WordPress Core


Ignore:
Timestamp:
07/07/2022 11:30:21 PM (2 years ago)
Author:
azaozz
Message:

Media:

  • Deprecate wp_get_attachment_thumb_file().
  • Make wp_get_attachment_thumb_url() an alias of wp_get_attachment_image_url(). This fixes it to return the proper thumbnail URL and fall back to returning the URL to image_meta['thumb'] if only that exists.

Props: markhowellsmead, mukesh27, csesumonpro, SergeyBiryukov, mikeschroder, killua99, joemcgill, mashukushibiki, mfgmicha, swissspidy, romulodl, nacin, JoshuaAbenazer, wonderboymusic, lonnylot, azaozz.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/deprecated.php

    r53455 r53685  
    43124312    _deprecated_function( __FUNCTION__, '6.0.0' );
    43134313}
     4314
     4315/**
     4316 * Retrieves thumbnail for an attachment.
     4317 * Note that this works only for the (very) old image metadata style where 'thumb' was set,
     4318 * and the 'sizes' array did not exist. This function returns false for the newer image metadata style
     4319 * despite that 'thumbnail' is present in the 'sizes' array.
     4320 *
     4321 * @since 2.1.0
     4322 * @deprecated 6.1.0
     4323 *
     4324 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
     4325 * @return string|false Thumbnail file path on success, false on failure.
     4326 */
     4327function wp_get_attachment_thumb_file( $post_id = 0 ) {
     4328    _deprecated_function( __FUNCTION__, '6.1.0' );
     4329
     4330    $post_id = (int) $post_id;
     4331    $post    = get_post( $post_id );
     4332
     4333    if ( ! $post ) {
     4334        return false;
     4335    }
     4336
     4337    // Use $post->ID rather than $post_id as get_post() may have used the global $post object.
     4338    $imagedata = wp_get_attachment_metadata( $post->ID );
     4339
     4340    if ( ! is_array( $imagedata ) ) {
     4341        return false;
     4342    }
     4343
     4344    $file = get_attached_file( $post->ID );
     4345
     4346    if ( ! empty( $imagedata['thumb'] ) ) {
     4347        $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
     4348        if ( file_exists( $thumbfile ) ) {
     4349            /**
     4350             * Filters the attachment thumbnail file path.
     4351             *
     4352             * @since 2.1.0
     4353             *
     4354             * @param string $thumbfile File path to the attachment thumbnail.
     4355             * @param int    $post_id   Attachment ID.
     4356             */
     4357            return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     4358        }
     4359    }
     4360
     4361    return false;
     4362}
Note: See TracChangeset for help on using the changeset viewer.