gpt4 book ai didi

WordPress:上传时发生错误

转载 作者:行者123 更新时间:2023-12-02 23:44:29 25 4
gpt4 key购买 nike

更新到 WordPress 3.5 后,我在以非管理员用户身份使用“添加媒体”按钮上传文件时开始收到以下错误:

Error: An error occurred in the upload. Please try again later.

图像似乎已完成上传,但在最后出现此错误消息。

这种情况不会发生在管理员身上,只会发生在其他角色身上。我什至尝试为其他角色提供完整的管理权限,但错误仍然出现。

这是一个错误吗?或者我错过了什么?

最佳答案

经过多次尝试和错误,我终于找到了一个适合我的解决方案。

首先,我发现上传自定义用户角色的文件需要以下角色功能:

$capabilites = array(

'read' => true,
'upload_files' => true,
'edit_published_pages' => true,
'edit_others_pages' => true

);

我不确定为什么特别需要这些,但如果没有它们,错误就会不断发生。

其次,我必须更新我用来防止非管理员用户访问仪表板的功能:

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,但新的媒体 uploader 使用 async-upload.php。

因此,本质上,这允许非管理员用户从前端使用新媒体 uploader ,而无需访问仪表板。

它还限制了他们对媒体库的访问,这对我来说也很重要。

关于WordPress:上传时发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14767629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com