Advertisements

wp_attachment_is_image

Definition:
function wp_attachment_is_image( $post_id = 0 ) {}

Check if the attachment is an image.

Parameters

  • int $post_id: Attachment ID

Source code

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', '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;

}

3425

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: