Media: Introduce a filter for wp_get_attachment_image()
HTML output.
Props prionkor, antpb, donmhico, audrasjb, Mista-Flo, hellofromTonya. Fixes #50801. git-svn-id: https://develop.svn.wordpress.org/trunk@49234 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a0be3a4ca7
commit
2defb1ef6c
@ -992,7 +992,7 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an HTML img element representing an image attachment
|
* Get an HTML img element representing an image attachment.
|
||||||
*
|
*
|
||||||
* While `$size` will accept an array, it is better to register a size with
|
* While `$size` will accept an array, it is better to register a size with
|
||||||
* add_image_size() so that a cropped version is generated. It's much more
|
* add_image_size() so that a cropped version is generated. It's much more
|
||||||
@ -1099,7 +1099,20 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f
|
|||||||
$html .= ' />';
|
$html .= ' />';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $html;
|
/**
|
||||||
|
* HTML img element representing an image attachment.
|
||||||
|
*
|
||||||
|
* @since 5.6.0
|
||||||
|
*
|
||||||
|
* @param string $html HTML img element or empty string on failure.
|
||||||
|
* @param int $attachment_id Image attachment ID.
|
||||||
|
* @param string|int[] $size Requested image size. Can be any registered image size name, or
|
||||||
|
* an array of width and height values in pixels (in that order).
|
||||||
|
* @param bool $icon Whether the image should be treated as an icon.
|
||||||
|
* @param array $attr Array of attribute values for the image markup, keyed by attribute name.
|
||||||
|
* See wp_get_attachment_image().
|
||||||
|
*/
|
||||||
|
return apply_filters( 'wp_get_attachment_image', $html, $attachment_id, $size, $icon, $attr );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1343,6 +1343,24 @@ EOF;
|
|||||||
$this->assertSame( $expected, wp_get_attachment_image( self::$large_id ) );
|
$this->assertSame( $expected, wp_get_attachment_image( self::$large_id ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 50801
|
||||||
|
*/
|
||||||
|
function test_wp_get_attachment_image_filter_output() {
|
||||||
|
$image = image_downsize( self::$large_id, 'thumbnail' );
|
||||||
|
$expected = 'Override wp_get_attachment_image';
|
||||||
|
|
||||||
|
add_filter( 'wp_get_attachment_image', array( $this, 'filter_wp_get_attachment_image' ) );
|
||||||
|
$output = wp_get_attachment_image( self::$large_id );
|
||||||
|
remove_filter( 'wp_get_attachment_image', array( $this, 'filter_wp_get_attachment_image' ) );
|
||||||
|
|
||||||
|
$this->assertSame( $expected, $output );
|
||||||
|
}
|
||||||
|
|
||||||
|
function filter_wp_get_attachment_image() {
|
||||||
|
return 'Override wp_get_attachment_image';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that `wp_get_attachment_image()` returns a proper alt value.
|
* Test that `wp_get_attachment_image()` returns a proper alt value.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user