[wp-trac] [WordPress Trac] #51228: Include support for the AVIF image format

WordPress Trac noreply at wordpress.org
Sat Jan 28 15:35:53 UTC 2023


#51228: Include support for the AVIF image format
--------------------------+------------------------------
 Reporter:  lukefiretoss  |       Owner:  adamsilverstein
     Type:  enhancement   |      Status:  assigned
 Priority:  normal        |   Milestone:  Future Release
Component:  Media         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by nickpagz):

 >I had to manually upload all files to my server outside the WordPress
 media library and link each image as a URL external to WordPress

 @gregbenz If it helps any, I've had to come up with some code for another
 site to make that process easier. Drop the code below into a snippets
 plugin or your child theme's functions.php file and you'll be able to
 upload to the media library just the same as any other image. Keep in mind
 there's no thumbnail generation, so you'll need to generate your different
 sizes offline and manually add each where you need them.


 {{{
 /**
 * Add Mime Type
 */

 function t51_add_avif_mime_type( $mime_types ) {
 $mime_types['avif'] = 'image/avif';

 return $mime_types;
 }
 add_filter( 'upload_mimes', 't51_add_avif_mime_type', 1, 1 );

 /**
 * Check Mime Type
 */
 function t51_avif_upload_check( $checked, $file, $filename, $mimes ) {

         if ( ! $checked['type'] ) {

                 $check_filetype  = wp_check_filetype( $filename, $mimes );
                 $ext             = $check_filetype['ext'];
                 $type            = $check_filetype['type'];
                 $proper_filename = $filename;

                 if ( $type && 0 === strpos( $type, 'image/' ) && $ext !==
 'avif' ) {
                         $ext = $type = false;
                 }

                 $checked = compact( 'ext','type','proper_filename' );
         }

         return $checked;

 }

 add_filter( 'wp_check_filetype_and_ext', 't51_avif_upload_check', 10, 4 );

 }}}

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


More information about the wp-trac mailing list