/*
Theme Name: Betheme Child
Theme URI: https://themes.muffingroup.com/betheme
Author: Muffin group
Author URI: https://muffingroup.com
Description: Child Theme for Betheme
Template: betheme
Version: 2.0
*/
function add_webp_upload_mime( $mimes ) {

    $mimes['webp'] = 'image/webp';

    return $mimes;

}

add_filter( 'mime_types', 'add_webp_upload_mime' );

function webp_is_displayable($result, $path) {

    if ($result === false) {

        $displayable_image_types = array( IMAGETYPE_WEBP );

        $info = @getimagesize( $path );

        if (empty($info)) {

            $result = false;

        } elseif (!in_array($info[2], $displayab

e_image_types)) {

            $result = false;

        } else {

            $result = true;

        }

    }

  return $result;

}

add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);


function display_webp_in_media_library( $result, $path ) {

    if ( $result === false ) {

        $displayable_image_types = array( IMAGETYPE_WEBP );

        $info = @getimagesize( $path );

        if ( empty( $info ) ) {

            $result = false;

        } elseif ( ! in_array( $info[2], $displayable_image_types ) ) {

            $result = false;

        } else {

            $result = true;

        }

    }

    return $result;

}

add_filter( 'file_is_displayable_image', 'display_webp_in_media_library', 10, 2 );