Wordpress:上传时发生错误 [英] Wordpress: An error occurred in the upload
问题描述
更新到 WordPress 3.5 后,我在以非管理员用户身份使用添加媒体"按钮上传文件时开始收到以下错误:
After updating to WordPress 3.5, I started getting the following error when uploading files using the Add Media button as a non-admin user:
错误:上传时发生错误.请稍后重试.
图片似乎已经上传完毕,但在最后出现此错误消息.
The image seems to finish uploading, but right at the end this error message appears.
这不会发生在管理员身上,只会发生在其他角色身上.我什至尝试为另一个角色提供完整的管理权限,但错误仍然出现.
This doesn't happen for the administrator, only the other roles. I've even tried giving the other role full admin capabilities, but the error still appears.
这是一个错误吗?还是我遗漏了什么?
Is this a bug? Or am I missing something?
推荐答案
经过反复试验,我终于找到了适合我的解决方案.
After much trial and error, I finally found a solution that worked for me.
首先,我发现上传自定义用户角色的文件需要以下角色能力:
First, I found the following role capabilities to be required to upload files for custom user roles:
$capabilites = array(
'read' => true,
'upload_files' => true,
'edit_published_pages' => true,
'edit_others_pages' => true
);
我不确定为什么特别需要这些,但如果没有它们,错误就会不断发生.
I'm not sure why these are specifically required, but the error kept occurring without them.
其次,我必须更新我用来防止非管理员用户访问仪表板的功能:
Second, I had to update a function I was using to prevent non-admin users from accessing the Dashboard:
function redirect_nonadmin_fromdash(){
if($_SERVER['PHP_SELF'] == '/wp-admin/async-upload.php'){
/* allow users to upload files */
return true;
} else if(get_user_role() != 'administrator'){
/* custom function get_user_role() checks user role,
requires administrator, else redirects */
wp_safe_redirect(home_url());
exit;
}
}
add_action( 'login_form_login', 'redirect_nonadmin_fromdash' );
add_action( 'admin_init', 'redirect_nonadmin_fromdash', 1 );
之前,我正在检查 media-upload.php,但新的媒体上传器使用 async-upload.php.
Previously, I was checking for the media-upload.php, but the new media uploader uses async-upload.php.
因此,本质上,这允许非管理员用户从前端使用新媒体上传器,而不允许他们访问仪表板.
So, essentially, this allows non-admin users to use the new media uploader from the front-end without allowing them access to the Dashboard.
它还限制了他们对媒体库的访问,这对我来说也很重要.
It also restricts their access to the Media Library, which was also important to me.
这篇关于Wordpress:上传时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!