Created
June 16, 2017 14:35
-
-
Save panoslyrakis/9861a7c99f5d2f9cb025063618e109c3 to your computer and use it in GitHub Desktop.
Add more mimes to support system. When nothing else works we can use map_meta_cap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'map_meta_cap', function( $caps, $cap, $user_id, $args ){ | |
if( ! isset( $_FILES['support-attachment'] ) ){ | |
return $caps; | |
} | |
$allowed_mimes = array( | |
'jpg' =>'image/jpg', | |
'jpeg' =>'image/jpeg', | |
'gif' => 'image/gif', | |
'png' => 'image/png', | |
'zip' => 'application/zip', | |
'gz|gzip' => 'application/x-gzip', | |
'rar' => 'application/rar', | |
'pdf' => 'application/pdf', | |
'txt' => 'text/plain', | |
'doc' => 'application/msword', | |
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | |
'ppt' => 'application/vnd.ms-powerpoint', | |
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | |
); | |
$allowed_extensions = array( 'jpg', 'jpeg', 'gif', 'png', 'zip', 'gz|gzip', 'rar', 'pdf', 'txt', 'doc', 'docx', 'ppt', 'pptx' ); | |
$filename = $_FILES['support-attachment']['name'][0]; | |
$filetype = $_FILES['support-attachment']['type'][0]; | |
$ext = pathinfo( $filename, PATHINFO_EXTENSION ); | |
if( ! in_array( $ext, $allowed_extensions ) || ! isset( $allowed_mimes[ $ext ] ) || $allowed_mimes[ $ext ] != $filetype ) { | |
return $caps; | |
} | |
if ( $cap == 'unfiltered_upload' ) { | |
//If we use membership we can limit cap to members | |
$args = array( | |
'user_id' => $user_id, | |
); | |
$args['meta_query']['status'] = array( | |
'key' => 'status', | |
'value' => array( 'trial_expired', 'expired' ), | |
'compare' => 'NOT IN', | |
); | |
$user_subscriptions = MS_Model_Relationship::get_subscriptions( $args ); | |
if( ! empty( $user_subscriptions ) ){ | |
$caps = array(); | |
$caps[] = $cap; | |
} | |
} | |
return $caps; | |
}, 99999, 4 ); | |
add_filter( 'incsub_support_allowed_mime_types', function( $mime_types ){ | |
$mime_types[ 'doc' ] = 'application/msword'; | |
$mime_types[ 'docx' ] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; | |
$mime_types[ 'ppt' ] = 'application/vnd.ms-powerpoint'; | |
$mime_types[ 'pptx' ] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; | |
return $mime_types; | |
}, 99999, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment