The problem seems to be quite common, yet most of the solutions on the net are nothing to do with my issue.
So I have custom post type where on the front end users can add a post and upload an image in that post. I'm using the following script to allow access for the subscribers to upload media:
function add_media_cap()
{
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if ($user_role == 'subscriber') {
$subscriber = get_role('subscriber');
$subscriber->add_cap('upload_files');
$subscriber->add_cap('edit_files');
}
}
add_action('init', 'add_media_cap');
Also have this one too, to restrict them from seeing someone else media:
function show_current_user_attachments($query)
{
$user_id = get_current_user_id();
if ($user_id) {
$query['author'] = $user_id;
}
return $query;
}
add_filter('ajax_query_attachments_args', 'show_current_user_attachments',10, 1);
Thing is that with admin account I can upload image with no problem. But subscribers can't, and they get the above mentioned error. I have checked the response from 'async-upload.php' and it is empty. Empty is also the console log in the developers tools, empty is the error log. All file permissions are as they should be.
Any help would be welcomed.