-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-nextgenimg-support.php
71 lines (62 loc) · 1.74 KB
/
wp-nextgenimg-support.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
*
* @package wpnextgenimgsupport
*
* Plugin Name: WordPress Next Gen. Image Support
* Plugin URI: https://github.com/rolandfarkasCOM/wp-webp-support
* Description: WordPress Next Gen. Image Support (WebP, JP2).
* Version: 1.2.0
* Author: Roland Farkas
* Author URI: https://rolandfarkas.com
* Text Domain: wowebpsupport
* License: GNU General Public License v3.0
* URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
if ( ! defined( 'ABSPATH' ) ) die( 'Hey, you can`t access this file, you silly human!' );
/**
*
* Sets the extension and mime type for .webp files.
*
*/
add_filter( 'wp_check_filetype_and_ext', 'wpnextgenimgsupport_file_and_ext_webp', 10, 4 );
function wpnextgenimgsupport_file_and_ext_webp( $types, $file, $filename, $mimes ) {
if ( false !== strpos( $filename, '.webp' ) ) {
$types['ext'] = 'webp';
$types['type'] = 'image/webp';
}
return $types;
}
/**
*
* Adds webp filetype to allowed mimes
*
*/
add_filter( 'upload_mimes', 'wpnextgenimgsupport_mime_types_webp' );
function wpnextgenimgsupport_mime_types_webp( $mimes ) {
$mimes['webp'] = 'image/webp';
return $mimes;
}
/**
*
* Sets the extension and mime type for .jp2 files.
*
*/
add_filter( 'wp_check_filetype_and_ext', 'wpnextgenimgsupport_file_and_ext_jp2', 10, 4 );
function wpnextgenimgsupport_file_and_ext_jp2( $types, $file, $filename, $mimes ) {
if ( false !== strpos( $filename, '.jp2' ) ) {
$types['ext'] = 'jp2';
$types['type'] = 'image/jp2';
}
return $types;
}
/**
*
* Adds webp filetype to allowed mimes
*
*/
add_filter( 'upload_mimes', 'wpnextgenimgsupport_mime_types_jp2' );
function wpnextgenimgsupport_mime_types_jp2( $mimes ) {
$mimes['jp2'] = 'image/jp2';
return $mimes;
}