| @@ -1,55 +1,48 @@ | ||
| 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; | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | + | |
| 6 | +// Allow some additional file types for upload. | |
| 7 | +function stp_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', 'stp_mime_types' ); | |
| 15 | + | |
| 16 | +function stp_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', 'stp_add_allow_upload_extension_exception', 10, 5 ); | |
| 45 | +} else { | |
| 46 | + add_filter( 'wp_check_filetype_and_ext', 'stp_add_allow_upload_extension_exception', 10, 4 ); | |
| 47 | +} | |
| 48 | + | |