| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
//allow some additional file types for upload |
| 5 |
function bplugins_stp_mime_types( $mimes ) { |
| 6 |
|
| 7 |
// New allowed mime types. |
| 8 |
$mimes['pls'] = 'audio/x-scpls'; |
| 9 |
$mimes['m3u8'] = 'application/vnd.apple.mpegurl'; |
| 10 |
|
| 11 |
|
| 12 |
return $mimes; |
| 13 |
} |
| 14 |
add_filter( 'upload_mimes', 'bplugins_stp_mime_types' ); |
| 15 |
|
| 16 |
|
| 17 |
// // Using in add_allow_upload_extension_exception function. |
| 18 |
// function wamt_remove_underscore($filename, $filename_raw){ |
| 19 |
// return str_replace("_.", ".", $filename); |
| 20 |
// } |
| 21 |
// add_filter( 'sanitize_file_name', 'wamt_remove_underscore', 10, 2 ); |
| 22 |
|
| 23 |
|
| 24 |
function bplugins_stp_add_allow_upload_extension_exception($data, $file, $filename,$mimes,$real_mime=null){ |
| 25 |
// If file extension is 2 or more |
| 26 |
$f_sp = explode(".", $filename); |
| 27 |
$f_exp_count = count ($f_sp); |
| 28 |
|
| 29 |
if($f_exp_count <= 1){ |
| 30 |
return $data; |
| 31 |
}else{ |
| 32 |
$f_name = $f_sp[0]; |
| 33 |
$ext = $f_sp[$f_exp_count - 1]; |
| 34 |
} |
| 35 |
|
| 36 |
if($ext == 'pls'){ |
| 37 |
$type = 'audio/x-scpls'; |
| 38 |
$proper_filename = ''; |
| 39 |
return compact('ext', 'type', 'proper_filename'); |
| 40 |
}else if($ext == 'm3u8'){ |
| 41 |
$type = 'application/vnd.apple.mpegurl'; |
| 42 |
$proper_filename = ''; |
| 43 |
return compact('ext', 'type', 'proper_filename'); |
| 44 |
}else { |
| 45 |
return $data; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
// It's different arguments between WordPress 5.1 and previous versions. |
| 50 |
global $wp_version; |
| 51 |
if ( version_compare( $wp_version, '5.1') >= 0): |
| 52 |
add_filter( 'wp_check_filetype_and_ext', 'bplugins_stp_add_allow_upload_extension_exception',10,5); |
| 53 |
else: |
| 54 |
add_filter( 'wp_check_filetype_and_ext', 'bplugins_stp_add_allow_upload_extension_exception',10,4); |
| 55 |
endif; |
| 56 |
|