Add a filter in `wp_get_attachment_image_src()` called `attachment_image_src`.

Props eclev91, MikeHansenMe.
Fixes #32363.

Built from https://develop.svn.wordpress.org/trunk@32866


git-svn-id: http://core.svn.wordpress.org/trunk@32837 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-06-19 21:27:25 +00:00
parent cfe78e0e95
commit ec6dfc7f2b
2 changed files with 25 additions and 13 deletions

View File

@ -693,23 +693,35 @@ 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 ) ) {
/** This filter is documented in wp-includes/post.php */ /** This filter is documented in wp-includes/post.php */
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
$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 );
} }
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-32865'; $wp_version = '4.3-alpha-32866';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.