Make WordPress Core


Ignore:
Timestamp:
06/19/2015 09:26:30 PM (11 years ago)
Author:
wonderboymusic
Message:

Add a filter in wp_get_attachment_image_src() called attachment_image_src.

Props eclev91, MikeHansenMe.
Fixes #32363.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r32787 r32866  
    694694 */
    695695function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
    696 
    697696        // get a thumbnail or intermediate image if there is one
    698         if ( $image = image_downsize($attachment_id, $size) )
    699                 return $image;
    700 
    701         $src = false;
    702 
    703         if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
    704                 /** This filter is documented in wp-includes/post.php */
    705                 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
    706 
    707                 $src_file = $icon_dir . '/' . wp_basename($src);
    708                 @list($width, $height) = getimagesize($src_file);
    709         }
    710         if ( $src && $width && $height )
    711                 return array( $src, $width, $height );
    712         return false;
     697        $image = image_downsize( $attachment_id, $size );
     698        if ( ! $image ) {
     699                $src = false;
     700
     701                if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) {
     702                        /** This filter is documented in wp-includes/post.php */
     703                        $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
     704
     705                        $src_file = $icon_dir . '/' . wp_basename( $src );
     706                        @list( $width, $height ) = getimagesize( $src_file );
     707                }
     708
     709                if ( $src && $width && $height ) {
     710                        $image = array( $src, $width, $height );
     711                }
     712        }
     713        /**
     714         * Filter the image src result
     715         *
     716         * @since 4.3.0
     717         *
     718         * @param array|false   $image          Either array with src, width & height, icon src, or false.
     719         * @param int           $attachment_id  Image attachment ID.
     720         * @param string|array  $size           Optional. Registered image size to retrieve the source for or a flat
     721         *                                      array of height and width dimensions. Default 'thumbnail'.
     722         * @param bool          $icon           Optional. Whether the image should be treated as an icon. Default false.
     723         */
     724        return apply_filters( 'attachment_image_src', $image, $attachment_id, $size, $icon );
    713725}
    714726
Note: See TracChangeset for help on using the changeset viewer.