[wp-trac] [WordPress Trac] #35725: Add mime-type for Webp

WordPress Trac noreply at wordpress.org
Fri Nov 13 10:42:40 UTC 2020


#35725: Add mime-type for Webp
-------------------------------------------------+-------------------------
 Reporter:  markoheijnen                         |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Media                                |     Version:  3.5
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch 2nd-opinion needs-testing  |     Focuses:
  has-unit-tests needs-refresh                   |
-------------------------------------------------+-------------------------

Comment (by svenwordpress):

 I found a code to add a plugin which enables webp. Think that is the base,
 but there is much more needed to handle webp. Especially in Gutenberg
 there need to be block settings for it. The question for me is if it will
 be handled within an image block or as an own block. An own block would
 offer more possibilities.


 {{{
 <?php
 /**
 * Plugin Name: WEBP Enabling
 * Plugin URI:
 * Description: WEBP Enabling
 * Version: 1.0
 * Author: Sven Esser
 * Author URI:
 * Functions Included: webp_upload_mimes, webp_is_displayable
 **/

 //** *Enable upload for webp image files.*/
 function webp_upload_mimes($existing_mimes) {
 $existing_mimes['webp'] = 'image/webp';
 return $existing_mimes;
 }
 add_filter('mime_types', 'webp_upload_mimes');

 //** * Enable preview for webp image files.*/
 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], $displayable_image_types)) {
 $result = false;
 } else {
 $result = true;
 }
 }

 return $result;
 }
 add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);
 ?>
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/35725#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list