Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_attachment_is_image [ WordPress Function ]

wp_attachment_is_image ( $post_id = 0 )
Parameters:
  • (int) $post_id Attachment ID
Returns:
  • (bool)
Defined at:



Check if the attachment is an image.

Source


<?php
function wp_attachment_is_image$post_id ) {
    
$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_type06) || $ext && 'import' == $post->post_mime_type && in_array($ext$image_exts) )
        return 
true;
    return 
false;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics