On this page
file_is_displayable_image( string $path ): bool
Validates that file is suitable for displaying within a web page.
Parameters
$pathstring Required-
File path to test.
Return
bool True if suitable, false if not suitable.
Source
File: wp-admin/includes/image.php. View all references
function file_is_displayable_image( $path ) {
$displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP );
$info = wp_getimagesize( $path );
if ( empty( $info ) ) {
$result = false;
} elseif ( ! in_array( $info[2], $displayable_image_types, true ) ) {
$result = false;
} else {
$result = true;
}
/**
* Filters whether the current image is displayable in the browser.
*
* @since 2.5.0
*
* @param bool $result Whether the image can be displayed. Default true.
* @param string $path Path to the image.
*/
return apply_filters( 'file_is_displayable_image', $result, $path );
}
Hooks
- apply_filters( 'file_is_displayable_image',
bool $result ,string $path ) -
Filters whether the current image is displayable in the browser.
Related
Uses
| Uses | Description |
|---|---|
| wp_getimagesize() wp-includes/media.php | Allows PHP’s getimagesize() to be debuggable when necessary. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| wp_generate_attachment_metadata() wp-admin/includes/image.php | Generates attachment meta data and create image sub-sizes for images. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/file_is_displayable_image