Make WordPress Core

Ticket #20205: 20205.1.diff

File 20205.1.diff, 2.7 KB (added by ericlewis, 11 years ago)
  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index 135ee95..3520d73 100644
    a b function get_intermediate_image_sizes() { 
    643643}
    644644
    645645/**
    646  * Retrieve an image to represent an attachment.
    647  *
    648  * A mime icon for files, thumbnail or intermediate size for images.
     646 * Retrieve the image source and width/height for an attachment.
    649647 *
    650648 * @since 2.5.0
    651649 *
    652  * @param int $attachment_id Image attachment ID.
    653  * @param string $size Optional, default is 'thumbnail'.
    654  * @param bool $icon Optional, default is false. Whether it is an icon.
    655  * @return bool|array Returns an array (url, width, height), or false, if no image is available.
     650 * @param  int          $attachment_id Attachment ID.
     651 * @param  string $size Optional, default is 'thumbnail'.
     652 * @param  bool $icon   Optional, default is false. Whether to return the icon for the attachment's mime-type.
     653 * @return bool|array   Returns an array (url, width, height), or false, if no image is available.
    656654 */
    657 function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) {
    658 
    659         // get a thumbnail or intermediate image if there is one
    660         if ( $image = image_downsize($attachment_id, $size) )
    661                 return $image;
    662 
    663         $src = false;
     655function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
     656        $return = false;
     657        // If the attachment is an image, get an image.
     658        if ( wp_attachment_is_image( $attachment_id ) ) {
     659                $return = image_downsize( $attachment_id, $size );
     660        }
    664661
    665         if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
     662        if ( $icon && ! $return && $src = wp_mime_type_icon( $attachment_id ) ) {
    666663                /** This filter is documented in wp-includes/post.php */
    667664                $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
    668                 $src_file = $icon_dir . '/' . wp_basename($src);
    669                 @list($width, $height) = getimagesize($src_file);
     665                $src_file = $icon_dir . '/' . wp_basename( $src );
     666                @list( $width, $height ) = getimagesize( $src_file );
     667                $return = array( $src, $width, $height );
    670668        }
    671         if ( $src && $width && $height )
    672                 return array( $src, $width, $height );
    673         return false;
     669        /**
     670         * Filter the attachment image source array.
     671         *
     672         * @since 4.0.0
     673         *
     674         * @param array|false $return        An assoc. array containing the image's src, width and height,
     675         *                                   false if no attachment image was found.
     676         * @param int         $attachment_id Attachment ID.
     677         * @param string      $size          Image size.
     678         * @param bool        $icon          Whether to return the image as its mime-type icon.
     679         */
     680        return apply_filters( 'wp_attachment_image_src', $return, $attachment_id, $size, $icon );
    674681}
    675682
    676683/**