Last active
June 19, 2022 13:08
-
-
Save ofmarconi/54a66650cbdd479dc4d2633e0dcf5d4f to your computer and use it in GitHub Desktop.
Check if the upload file name contains .gif If it does, refuse to upload it to the media gallery (by askjarvis.io)
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
function wpse_check_file_type( $file ) { | |
$filetype = wp_check_filetype( $file['name'] ); | |
$ext = $filetype['ext']; | |
$type = $filetype['type']; | |
$proper_filename = $file['name']; | |
$wp_filetype = wp_check_filetype( $proper_filename, null ); | |
$ext = $wp_filetype['ext']; | |
$type = $wp_filetype['type']; | |
$proper_filename = preg_replace('/\.[^.]+$/', '', basename( $file['name'] ) ); | |
$filename = $proper_filename . '.' . $ext; | |
if ( $type == 'image/gif' ) { | |
$file['error'] = 'Sorry, GIF files are not allowed.'; | |
return $file; | |
} | |
return $file; | |
} | |
add_filter( 'wp_handle_upload_prefilter', 'wpse_check_file_type' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment