admin管理员组文章数量:1415137
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.
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.
Share Improve this question asked Aug 30, 2019 at 20:49 AleAle 1807 bronze badges1 Answer
Reset to default 0Oh, well, while writing the question I tried to copy the full link that takes the ajax call: example/wp-admin/async-upload.php
and noticed that for the subscibers it was taking the user to their account page while the admins where getting The link you followed has expired.
Notice on the screen. And then I got the 'Aha' moment - I was restricting no-admins from wp-admin
and redirected them to their account page. After removing this redirect it all worked.
本文标签: media39An error occurred in the upload Please try again later39 for users with different roles
版权声明:本文标题:media - 'An error occurred in the upload. Please try again later.' for users with different roles 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745198235a2647242.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论