-
Notifications
You must be signed in to change notification settings - Fork 0
/
caldera-fix.php
33 lines (29 loc) · 1.21 KB
/
caldera-fix.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
<?php
/**
* Plugin Name: Caldera Fix
* Plugin URI: https://github.com/zacnoo/caldera-fix
* Description: Fix for Caldera forms mime type.
* Version: 0.3.2
* Author: Zack Palmer (zacnoo)
*/
/**
* Support for 'text/plain' as the secondary(?) mime type of .json files
*/
add_filter( 'wp_check_filetype_and_ext', 'wpse323750_secondary_mime', 99, 4 );
function wpse323750_secondary_mime( $check, $file, $filename, $mimes ) {
if ( empty( $check['ext'] ) && empty( $check['type'] ) ) {
$secondary_mime = [ 'json' => 'application/json' ];
// Run another check, but only for our secondary mime and not on core mime types.
remove_filter( 'wp_check_filetype_and_ext', 'wpse323750_secondary_mime', 99, 4 );
$check = wp_check_filetype_and_ext( $file, $filename, $secondary_mime );
add_filter( 'wp_check_filetype_and_ext', 'wpse323750_secondary_mime', 99, 4 );
}
return $check;
}
function my_theme_custom_upload_mimes( $existing_mimes ) {
// Add json to the list of mime types.
$existing_mimes['json'] = 'application/json';
// Return the array back to the function with our added mime type.
return $existing_mimes;
}
add_filter( 'mime_types', 'my_theme_custom_upload_mimes' );