wp_attachment_is_image example

_deprecated_function( __FUNCTION__, '2.5.0', 'wp_get_attachment_image_src()' );
    $id = (int) $id;
    if ( !$post = get_post($id) )
        return false;

    $file = get_attached_file( $post->ID );

    if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) {
        // We have a thumbnail desired, specified and existing.
        $src_file = wp_basename($src);
    } elseif ( wp_attachment_is_image( $post->ID ) ) {
        // We have an image without a thumbnail.
        $src = wp_get_attachment_url( $post->ID );
        $src_file = & $file;
    } elseif ( $src = wp_mime_type_icon( $post->ID ) ) {
        // No thumb, no image. We'll look for a mime-related icon instead.
        /** This filter is documented in wp-includes/post.php */
        $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
        $src_file = $icon_dir . '/' . wp_basename($src);
    }

    

?> <div <?php post_class( 'wp-embed' ); ?>> <?php         $thumbnail_id = 0;

        if ( has_post_thumbnail() ) {
            $thumbnail_id = get_post_thumbnail_id();
        }

        if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) {
            $thumbnail_id = get_the_ID();
        }

        /** * Filters the thumbnail image ID for use in the embed template. * * @since 4.9.0 * * @param int|false $thumbnail_id Attachment ID, or false if there is none. */
        $thumbnail_id = apply_filters( 'embed_thumbnail_id', $thumbnail_id );

        
wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to upload files.' ) ) );
    }

    if ( empty( $_POST['attachment_id'] ) ) {
        wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) );
    }

    $attachment_id = (int) $_POST['attachment_id'];

    if ( ! empty( $_POST['_wp_upload_failed_cleanup'] ) ) {
        // Upload failed. Cleanup.         if ( wp_attachment_is_image( $attachment_id ) && current_user_can( 'delete_post', $attachment_id ) ) {
            $attachment = get_post( $attachment_id );

            // Created at most 10 min ago.             if ( $attachment && ( time() - strtotime( $attachment->post_date_gmt ) < 600 ) ) {
                wp_delete_attachment( $attachment_id, true );
                wp_send_json_success();
            }
        }
    }

    /* * Set a custom header with the attachment_id. * Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. */

function wp_get_original_image_path( $attachment_id$unfiltered = false ) {
    if ( ! wp_attachment_is_image( $attachment_id ) ) {
        return false;
    }

    $image_meta = wp_get_attachment_metadata( $attachment_id );
    $image_file = get_attached_file( $attachment_id$unfiltered );

    if ( empty( $image_meta['original_image'] ) ) {
        $original_image = $image_file;
    } else {
        $original_image = path_join( dirname( $image_file )$image_meta['original_image'] );
    }

    

    $media_dims = apply_filters( 'media_meta', $media_dims$post );

    $image_edit_button = '';

    if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
        $nonce             = wp_create_nonce( "image_editor-$post->ID" );
        $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
    }

    $attachment_url = get_permalink( $attachment_id );

    $item = " $type_html $toggle_links $order $display_title <table class='slidetoggle describe
$data['type']   = 'rich';
    $data['html']   = get_post_embed_html( $width$height$post );

    // Add post thumbnail to response if available.     $thumbnail_id = false;

    if ( has_post_thumbnail( $post->ID ) ) {
        $thumbnail_id = get_post_thumbnail_id( $post->ID );
    }

    if ( 'attachment' === get_post_type( $post ) ) {
        if ( wp_attachment_is_image( $post ) ) {
            $thumbnail_id = $post->ID;
        } elseif ( wp_attachment_is( 'video', $post ) ) {
            $thumbnail_id = get_post_thumbnail_id( $post );
            $data['type'] = 'video';
        }
    }

    if ( $thumbnail_id ) {
        list( $thumbnail_url$thumbnail_width$thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) );
        $data['thumbnail_url']                                      = $thumbnail_url;
        $data['thumbnail_width']                                    = $thumbnail_width;
        

function image_downsize( $id$size = 'medium' ) {
    $is_image = wp_attachment_is_image( $id );

    /** * Filters whether to preempt the output of image_downsize(). * * Returning a truthy value from the filter will effectively short-circuit * down-sizing the image, returning that value instead. * * @since 2.5.0 * * @param bool|array $downsize Whether to short-circuit the image downsize. * @param int $id Attachment ID for image. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). */

function wp_get_missing_image_subsizes( $attachment_id ) {
    if ( ! wp_attachment_is_image( $attachment_id ) ) {
        return array();
    }

    $registered_sizes = wp_get_registered_image_subsizes();
    $image_meta       = wp_get_attachment_metadata( $attachment_id );

    // Meta error?     if ( empty( $image_meta ) ) {
        return $registered_sizes;
    }

    
$data['caption'] = array(
                'raw'      => $post->post_excerpt,
                'rendered' => $caption,
            );
        }

        if ( in_array( 'alt_text', $fields, true ) ) {
            $data['alt_text'] = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
        }

        if ( in_array( 'media_type', $fields, true ) ) {
            $data['media_type'] = wp_attachment_is_image( $post->ID ) ? 'image' : 'file';
        }

        if ( in_array( 'mime_type', $fields, true ) ) {
            $data['mime_type'] = $post->post_mime_type;
        }

        if ( in_array( 'media_details', $fields, true ) ) {
            $data['media_details'] = wp_get_attachment_metadata( $post->ID );

            // Ensure empty details is an empty object.             if ( empty( $data['media_details'] ) ) {
                
Home | Imprint | This part of the site doesn't use cookies.