函数原型
file_is_displayable_image( string $path ): bool
函数描述
Validates that file is suitable for displaying within a web page.
是否弃用
未弃用
函数参数
-
$path
string
Required - File path to test.
函数返回值
bool True if suitable, false if not suitable.
函数位置
File: wp-admin/includes/image.php.
函数源码
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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |

