file_is_displayable_image

The timeline below displays how wordpress function file_is_displayable_image has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Validates that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $displayable_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP, IMAGETYPE_AVIF);
    $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);
}

WordPress Version: 6.1

/**
 * Validates that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
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);
}

WordPress Version: 5.9

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
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);
}

WordPress Version: 5.8

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $displayable_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP);
    // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound
    $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);
}

WordPress Version: 5.7

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $displayable_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO);
    $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);
}

WordPress Version: 5.3

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $displayable_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO);
    $info = @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);
}

WordPress Version: 5.1

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $displayable_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP);
    // IMAGETYPE_ICO is only defined in PHP 5.3+.
    if (defined('IMAGETYPE_ICO')) {
        $displayable_image_types[] = IMAGETYPE_ICO;
    }
    $info = @getimagesize($path);
    if (empty($info)) {
        $result = false;
    } elseif (!in_array($info[2], $displayable_image_types)) {
        $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);
}

WordPress Version: 4.6

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $displayable_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP);
    $info = @getimagesize($path);
    if (empty($info)) {
        $result = false;
    } elseif (!in_array($info[2], $displayable_image_types)) {
        $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);
}

WordPress Version: 4.0

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $displayable_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP);
    $info = @getimagesize($path);
    if (empty($info)) {
        $result = false;
    } elseif (!in_array($info[2], $displayable_image_types)) {
        $result = false;
    } else {
        $result = true;
    }
    /**
     * Filter 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);
}

WordPress Version: 3.9

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $info = @getimagesize($path);
    if (empty($info)) {
        $result = false;
    } elseif (!in_array($info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
        // only gif, jpeg and png images can reliably be displayed
        $result = false;
    } else {
        $result = true;
    }
    /**
     * Filter 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);
}

WordPress Version: 3.7

/**
 * Validate that file is suitable for displaying within a web page.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'file_is_displayable_image' on $result and $path.
 *
 * @param string $path File path to test.
 * @return bool True if suitable, false if not suitable.
 */
function file_is_displayable_image($path)
{
    $info = @getimagesize($path);
    if (empty($info)) {
        $result = false;
    } elseif (!in_array($info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
        // only gif, jpeg and png images can reliably be displayed
        $result = false;
    } else {
        $result = true;
    }
    return apply_filters('file_is_displayable_image', $result, $path);
}