wppaste
WordPress

wp_get_attachment_thumb_file( int $post_id = 0 ): string|false

Since
2.1.0
Source
wp-includes/deprecated.php:4346
Retrieves thumbnail for an attachment.

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

Reads or writes the filesystem via file_exists().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
13–46

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 49.

Plugin surface
1 hook

Third-party callbacks on 'wp_get_attachment_thumb_file' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • filesystemfilesystem accessfile_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.

WhenInstructionsCalls it makes
always13_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

PHPCompiledExecutedBranchesNotes
8.6-dev4913–464
8.54913–464
8.44913–4644 fewer instructions than PHP 8.3
8.35313–504
8.25313–504
8.15313–504
7.45313–504

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:

  1. apply_filters( wp_get_attachment_thumb_file )filterline 4376 (+30 into the body)

    Filters the attachment thumbnail file path.

Uses · 6

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.1.0
Deprecated.from the docblock
2.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 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.