wp_get_attachment_thumb_file( int $post_id = 0 ): string|false
- Since
- 2.1.0
- Source
wp-includes/deprecated.php:4346
Description
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.
Compatibility
Deprecated in WordPress 6.1.0. Kept for back-compatibility; avoid it in new code.
- WordPress
- since 2.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$post_idintoptional- Attachment ID. Default is the ID of the global
$post.Default:0
Return value
string|false- Thumbnail file path on success, false on failure.
Performance profile
How much work a call to wp_get_attachment_thumb_file() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 13–46
- Plugin surface
- 1 hook
- Called by
- 0
Reads or writes the filesystem via file_exists().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 49.
Third-party callbacks on 'wp_get_attachment_thumb_file' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - filesystemfilesystem access
file_exists()called directly
Further down the call graph this can also reach cache, serialize, option and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_attachment_thumb_file() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 13 | _deprecated_function(), get_post() |
!is_array($imagedata) | 21 | _deprecated_function(), get_post(), wp_get_attachment_metadata() |
is_array($imagedata) && empty($imagedata) | 29 | _deprecated_function(), get_post(), wp_get_attachment_metadata(), get_attached_file() |
is_array($imagedata) && !empty($imagedata) && !file_exists() | 39 | _deprecated_function(), get_post(), wp_get_attachment_metadata(), get_attached_file(), wp_basename(), file_exists() |
is_array($imagedata) && !empty($imagedata) && file_exists() | 46 | _deprecated_function(), get_post(), wp_get_attachment_metadata(), get_attached_file(), wp_basename(), file_exists(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 49 | 13–46 | 4 | |
| 8.5 | 49 | 13–46 | 4 | |
| 8.4 | 49 | 13–46 | 4 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 53 | 13–50 | 4 | |
| 8.2 | 53 | 13–50 | 4 | |
| 8.1 | 53 | 13–50 | 4 | |
| 7.4 | 53 | 13–50 | 4 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_get_attachment_thumb_file() runs, in this order:
- apply_filters( wp_get_attachment_thumb_file )filterline 4376 (+30 into the body)
Filters the attachment thumbnail file path.
Uses · 6
- _deprecated_function()Marks a function as deprecated and inform when it has been used.
- get_post()Retrieves post data given a post ID or post object.
- wp_get_attachment_metadata()Retrieves attachment metadata for attachment ID.
- get_attached_file()Retrieves attached file path based on attachment ID.
- wp_basename()i18n-friendly version of basename().
- apply_filters()Calls the callback functions that have been added to a filter hook.
Source code
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;}Changelog
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/deprecated.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.