Add a filter in wp_get_attachment_image_src() called attachment_image_src.

Props eclev91, MikeHansenMe.
Fixes #32363.


git-svn-id: https://develop.svn.wordpress.org/trunk@32866 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-06-19 21:26:30 +00:00
parent bb292c74c1
commit 9123db3dcb

View File

@ -693,11 +693,9 @@ function get_intermediate_image_sizes() {
* @return false|array Returns an array (url, width, height), or false, if no image is available. * @return false|array Returns an array (url, width, height), or false, if no image is available.
*/ */
function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) { function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
// get a thumbnail or intermediate image if there is one // get a thumbnail or intermediate image if there is one
if ( $image = image_downsize($attachment_id, $size) ) $image = image_downsize( $attachment_id, $size );
return $image; if ( ! $image ) {
$src = false; $src = false;
if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) { if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) {
@ -707,9 +705,23 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
$src_file = $icon_dir . '/' . wp_basename( $src ); $src_file = $icon_dir . '/' . wp_basename( $src );
@list( $width, $height ) = getimagesize( $src_file ); @list( $width, $height ) = getimagesize( $src_file );
} }
if ( $src && $width && $height )
return array( $src, $width, $height ); if ( $src && $width && $height ) {
return false; $image = array( $src, $width, $height );
}
}
/**
* Filter the image src result
*
* @since 4.3.0
*
* @param array|false $image Either array with src, width & height, icon src, or false.
* @param int $attachment_id Image attachment ID.
* @param string|array $size Optional. Registered image size to retrieve the source for or a flat
* array of height and width dimensions. Default 'thumbnail'.
* @param bool $icon Optional. Whether the image should be treated as an icon. Default false.
*/
return apply_filters( 'attachment_image_src', $image, $attachment_id, $size, $icon );
} }
/** /**