August 12, 2015 at 6:16 pm
#14317
Syam Mohan
Keymaster
function wpfront_custom_upload_prefilter( $file ) {
$roles_not_allowed = array('author', 'editor'); //not allowed role names
$user = wp_get_current_user();
foreach($roles_not_allowed as $role) {
if(in_array($role, $user->roles)) {
$file['error'] = 'You are not allowed to upload.';
return $file;
}
}
return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'wpfront_custom_upload_prefilter' );
The above code limits any user who belongs to Author or Editor from uploading. Make sure to change the role names to your role names.
Thanks
Syam