I'm using the WP Editor on a page outside of the admin section when allowing my users to create a post. I'm enabling it like this:
$editor_id = 'post_information';
wp_editor( $content, $editor_id );
I'm trying to limit the users to only be able to upload a .jpg, .png, .gif file and have the following code to do this:
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.";
}
return $file;
}
This works fine and will only allow my users to upload those file types. However, if I try and upload a plugin in a zip file or something within the dashboard section it hits this code and won't let me upload it. Is there a way to limit this for the WP Editor but not have it affect any of the admin dashboard uploads?
Aucun commentaire:
Enregistrer un commentaire