| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
// Allow some additional file types for upload. |
| 7 |
function streamcast_mime_types( $mimes ) { |
| 8 |
// New allowed mime types. |
| 9 |
$mimes['pls'] = 'audio/x-scpls'; |
| 10 |
$mimes['m3u8'] = 'application/vnd.apple.mpegurl'; |
| 11 |
|
| 12 |
return $mimes; |
| 13 |
} |
| 14 |
add_filter( 'upload_mimes', 'streamcast_mime_types' ); |
| 15 |
|
| 16 |
function streamcast_add_allow_upload_extension_exception( $data, $file, $filename, $mimes, $real_mime = null ) { |
| 17 |
// If file extension is 2 or more. |
| 18 |
$f_sp = explode( '.', $filename ); |
| 19 |
$f_exp_count = count( $f_sp ); |
| 20 |
|
| 21 |
if ( $f_exp_count <= 1 ) { |
| 22 |
return $data; |
| 23 |
} else { |
| 24 |
$f_name = $f_sp[0]; |
| 25 |
$ext = $f_sp[ $f_exp_count - 1 ]; |
| 26 |
} |
| 27 |
|
| 28 |
if ( 'pls' === $ext ) { |
| 29 |
$type = 'audio/x-scpls'; |
| 30 |
$proper_filename = ''; |
| 31 |
return compact( 'ext', 'type', 'proper_filename' ); |
| 32 |
} elseif ( 'm3u8' === $ext ) { |
| 33 |
$type = 'application/vnd.apple.mpegurl'; |
| 34 |
$proper_filename = ''; |
| 35 |
return compact( 'ext', 'type', 'proper_filename' ); |
| 36 |
} else { |
| 37 |
return $data; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
// It's different arguments between WordPress 5.1 and previous versions. |
| 42 |
global $wp_version; |
| 43 |
if ( version_compare( $wp_version, '5.1' ) >= 0 ) { |
| 44 |
add_filter( 'wp_check_filetype_and_ext', 'streamcast_add_allow_upload_extension_exception', 10, 5 ); |
| 45 |
} else { |
| 46 |
add_filter( 'wp_check_filetype_and_ext', 'streamcast_add_allow_upload_extension_exception', 10, 4 ); |
| 47 |
} |
| 48 |
|
| 49 |
|