Prevent PDF Media Uploads
-
Is there a way to override the media types mentioned http://codex.ww.wp.xz.cn/Uploading_Files#About_Uploading_Files_with_WordPress?
I would like to especially prevent other admin users from uploading PDFs, but also block the audio and video formats. We are hosting those media types on an external server for performance, but sometimes other users forget.
Viewing 3 replies - 1 through 3 (of 3 total)
-
This is kind of old, but I think it will still work…
If not, post back your results and maybe someone else can fix what’s here:
Perfect! Thanks. It also limited to 1 upload per post. I’ll yank that out for my needs.
add_filter('wp_handle_upload_prefilter', 'yoursite_wp_handle_upload_prefilter'); function yoursite_wp_handle_upload_prefilter($file) { // This bit is for the flash uploader if ($file['type']=='application/octet-stream' && isset($file['tmp_name'])) { $file_size = getimagesize($file['tmp_name']); if (isset($file_size['error']) && $file_size['error']!=0) { $file['error'] = "Unexpected Error: {$file_size['error']}"; return $file; } else { $file['type'] = $file_size['mime']; } } list($category,$type) = explode('/',$file['type']); if ('image'!=$category || !in_array($type,array('jpg','jpeg','gif','png'))) { $file['error'] = "Sorry, you can only upload a .GIF, a .JPG, or a .PNG image file."; } else if ($post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : false)) { if (count(get_posts("post_type=attachment&post_parent={$post_id}"))>0) $file['error'] = "Sorry, you cannot upload more than one (1) image."; } return $file; }Let me know if that works, or what you had to modify so others can use it, too!
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Prevent PDF Media Uploads’ is closed to new replies.