wp_attachment_is_image

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

WordPress Version: 5.1

/**
 * Determines whether an attachment is an image.
 *
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = null)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: 0.3

/**
 * Determines whether an attachment is an image.
 * 
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = null)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: .20

/**
 * Determines whether an attachment is an image.
 *
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = null)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: 0.2

/**
 * Determines whether an attachment is an image.
 * 
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = null)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: .18

/**
 * Determines whether an attachment is an image.
 *
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = null)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: 5.0

/**
 * Determines whether an attachment is an image.
 * 
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = null)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: 4.6

/**
 * Checks if the attachment is an image.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID or object. Default is global $post.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = null)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: 4.3

/**
 * Checks if the attachment is an image.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID. Default 0.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = 0)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: 4.2

/**
 * Checks if the attachment is an image.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is()
 *
 * @param int|WP_Post $post Optional. Attachment ID. Default 0.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = 0)
{
    return wp_attachment_is('image', $post);
}

WordPress Version: 4.0

/**
 * Check if the attachment is an image.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!$file = get_attached_file($post->ID)) {
        return false;
    }
    $ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false;
    $image_exts = array('jpg', 'jpeg', 'jpe', 'gif', 'png');
    if ('image/' == substr($post->post_mime_type, 0, 6) || $ext && 'import' == $post->post_mime_type && in_array($ext, $image_exts)) {
        return true;
    }
    return false;
}

WordPress Version: 3.7

/**
 * Check if the attachment is an image.
 *
 * @since 2.1.0
 *
 * @param int $post_id Attachment ID
 * @return bool
 */
function wp_attachment_is_image($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!$post = get_post($post_id)) {
        return false;
    }
    if (!$file = get_attached_file($post->ID)) {
        return false;
    }
    $ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false;
    $image_exts = array('jpg', 'jpeg', 'jpe', 'gif', 'png');
    if ('image/' == substr($post->post_mime_type, 0, 6) || $ext && 'import' == $post->post_mime_type && in_array($ext, $image_exts)) {
        return true;
    }
    return false;
}