wp_get_attachment_thumb_file

The timeline below displays how wordpress function wp_get_attachment_thumb_file has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * 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.
 *
 * @since 2.1.0
 * @deprecated 6.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
 * @return string|false Thumbnail file path on success, false on failure.
 */
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;
}

WordPress Version: 5.9

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
 * @return string|false Thumbnail file path on success, false on failure.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $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;
}

WordPress Version: 5.7

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false Thumbnail file path on success, false on failure.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $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;
}

WordPress Version: 5.3

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail file path on success.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $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;
}

WordPress Version: 5.2

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail file path on success.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!is_array($imagedata = wp_get_attachment_metadata($post->ID))) {
        return false;
    }
    $file = get_attached_file($post->ID);
    if (!empty($imagedata['thumb']) && ($thumbfile = str_replace(wp_basename($file), $imagedata['thumb'], $file)) && 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;
}

WordPress Version: 4.6

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail file path on success.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!is_array($imagedata = wp_get_attachment_metadata($post->ID))) {
        return false;
    }
    $file = get_attached_file($post->ID);
    if (!empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && 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;
}

WordPress Version: 4.3

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail file path on success.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!is_array($imagedata = wp_get_attachment_metadata($post->ID))) {
        return false;
    }
    $file = get_attached_file($post->ID);
    if (!empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile)) {
        /**
         * Filter 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;
}

WordPress Version: 4.0

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return mixed False on failure. Thumbnail file path on success.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!is_array($imagedata = wp_get_attachment_metadata($post->ID))) {
        return false;
    }
    $file = get_attached_file($post->ID);
    if (!empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile)) {
        /**
         * Filter 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;
}

WordPress Version: 3.9

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Attachment ID.
 * @return mixed False on failure. Thumbnail file path on success.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!is_array($imagedata = wp_get_attachment_metadata($post->ID))) {
        return false;
    }
    $file = get_attached_file($post->ID);
    if (!empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile)) {
        /**
         * Filter 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;
}

WordPress Version: 3.7

/**
 * Retrieve thumbnail for an attachment.
 *
 * @since 2.1.0
 *
 * @param int $post_id Attachment ID.
 * @return mixed False on failure. Thumbnail file path on success.
 */
function wp_get_attachment_thumb_file($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!is_array($imagedata = wp_get_attachment_metadata($post->ID))) {
        return false;
    }
    $file = get_attached_file($post->ID);
    if (!empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile)) {
        return apply_filters('wp_get_attachment_thumb_file', $thumbfile, $post->ID);
    }
    return false;
}