Advertisement
Aurangajeb

Add custom file type in wp (i.e: webP)

Aug 14th, 2021
1,556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. //** *Enable upload for webp image files.*/
  2. function webp_upload_mimes($existing_mimes) {
  3.     $existing_mimes['webp'] = 'image/webp';
  4.     return $existing_mimes;
  5. }
  6. add_filter('mime_types', 'webp_upload_mimes');
  7.  
  8. //** * Enable preview for webp image files.*/
  9. function webp_is_displayable($result, $path) {
  10.     if ($result === false) {
  11.     $displayable_image_types = array( IMAGETYPE_WEBP );
  12.     $info = @getimagesize( $path );
  13.  
  14. if (empty($info)) {
  15.     $result = false;
  16. } elseif (!in_array($info[2], $displayable_image_types)) {
  17.     $result = false;
  18. } else {
  19.     $result = true;
  20. }
  21. }
  22. return $result;
  23.  
  24. }
  25. add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement