WordPress.org

Make WordPress Core

Ticket #20205: media.php.2.patch

File media.php.2.patch, 1.6 KB (added by doublesharp, 6 years ago)

wp_get_attachment_image_src filter in wp_get_attachment_image_src() function

  • wp-includes/media.php

     
    491491 *
    492492 * A mime icon for files, thumbnail or intermediate size for images.
    493493 *
     494 * @uses apply_filters() Calls 'wp_get_attachment_image_src' hook on image array
    494495 * @since 2.5.0
    495496 *
    496497 * @param int $attachment_id Image attachment ID.
     
    501502function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) {
    502503
    503504        // get a thumbnail or intermediate image if there is one
    504         if ( $image = image_downsize($attachment_id, $size) )
    505                 return $image;
     505        if (false === ( $image = image_downsize($attachment_id, $size) ) ) {
     506                $src = false;
    506507
    507         $src = false;
    508 
    509         if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
    510                 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
    511                 $src_file = $icon_dir . '/' . wp_basename($src);
    512                 @list($width, $height) = getimagesize($src_file);
     508                if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
     509                        $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
     510                        $src_file = $icon_dir . '/' . wp_basename($src);
     511                        @list($width, $height) = getimagesize($src_file);
     512                }
     513                if ( $src && $width && $height )
     514                        $image = array( $src, $width, $height );
    513515        }
    514         if ( $src && $width && $height )
    515                 return array( $src, $width, $height );
     516        $image = apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
     517        if (!empty($image))
     518                return $image;
    516519        return false;
    517520}
    518521