wp_get_attachment_thumb_file()WP 2.1.0

Deprecated since 6.1.0. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

Retrieves thumbnail for an attachment. Note that this works only for the (very) old image metadata style where 'thumb' was set, and the 'sizes' array did not exist. This function returns false for the newer image metadata style despite that 'thumbnail' is present in the 'sizes' array.

Hooks from the function

Returns

String|false. Thumbnail file path on success, false on failure.

Usage

wp_get_attachment_thumb_file( $post_id );
$post_id(int)
Attachment ID.
Default: ID of the global $post

Changelog

Since 2.1.0 Introduced.
Deprecated since 6.1.0

wp_get_attachment_thumb_file() code WP 6.8.1

function wp_get_attachment_thumb_file( $post_id = 0 ) {
	_deprecated_function( __FUNCTION__, '6.1.0' );

	$post_id = (int) $post_id;
	$post    = get_post( $post_id );

	if ( ! $post ) {
		return false;
	}

	// Use $post->ID rather than $post_id as get_post() may have used the global $post object.
	$imagedata = wp_get_attachment_metadata( $post->ID );

	if ( ! is_array( $imagedata ) ) {
		return false;
	}

	$file = get_attached_file( $post->ID );

	if ( ! empty( $imagedata['thumb'] ) ) {
		$thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
		if ( file_exists( $thumbfile ) ) {
			/**
			 * Filters the attachment thumbnail file path.
			 *
			 * @since 2.1.0
			 *
			 * @param string $thumbfile File path to the attachment thumbnail.
			 * @param int    $post_id   Attachment ID.
			 */
			return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
		}
	}

	return false;
}