wp_attachment_is_image( int|WP_Post $post = null ): bool
- Since
- 2.1.0, 4.2.0
- Source
wp-includes/post.php:7169
Description
For more information on this and similar theme functions, check out the https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags article in the Theme Developer Handbook.
Compatibility
- WordPress
- since 4.2.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
$postint|WP_Postoptional- Attachment ID or object. Default is global $post.Default:
null
Return value
bool- Whether the attachment is an image.
Performance profile
How much work a call to wp_attachment_is_image() 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
- 6
- Plugin surface
- None
- Called by
- 16
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 6.
Nothing here hands control to plugin code.
16 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()one call below wp_attachment_is_image()
Further down the call graph this can also reach hook, 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_attachment_is_image() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6 | wp_attachment_is() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 6 instructions, 6 executed per call, 0 branches. The work does not change between versions.
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.
Uses · 1
- wp_attachment_is()Verifies an attachment is of a given type.
Used by · 16
- WP_REST_Attachments_Controller::prepare_item_for_response()Prepares a single attachment output for response.
- edit_form_image_editor()Displays the image and editor in the post editor
- get_attachment_icon_src()Retrieve icon URL and Path.
- get_media_item()Retrieves HTML form for modifying the image attachment.
- get_oembed_response_data_rich()Filters the oEmbed response data to return an iframe embed code.
- has_custom_logo()Determines whether the site has a custom logo.
- image_downsize()Scales an image to fit a particular size (such as 'thumb' or 'medium').
- twentyfifteen_entry_meta()Prints HTML with meta information for the categories, tags.
- twentyfifteen_scripts()Enqueues scripts and styles.
- twentyfourteen_content_width()Adjusts content_width value for image attachment template.
- twentyfourteen_scripts()Enqueues scripts and styles for the front end.
- twentysixteen_scripts()Enqueues scripts and styles.
Show all 16
- wp_ajax_media_create_image_subsizes()Handles creating missing image sub-sizes for just uploaded images via AJAX.
- wp_get_missing_image_subsizes()Compare the existing image sub-sizes (as saved in the attachment meta) to the currently registered image sub-sizes, and return the difference.
- wp_get_original_image_path()Retrieves the path to an uploaded image file.
- wp_get_original_image_url()Retrieves the URL to an original attachment image.
Source code
function wp_attachment_is_image( $post = null ) { return wp_attachment_is( 'image', $post );}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 7.0.4 tag, from
src/wp-includes/post.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.