我在 woocommerce“查看订单”页面中使用
acf_form()
(高级自定义字段前端表单)创建了一个前端表单,它允许客户为我们上传一些文件,该表单对管理员来说工作正常但是当您登录时- 使用客户帐户并选择您的文件,它显示“您无权附加文件”,经过一些研究后,我通过将以下代码添加到"customer"
来编辑functions.php
:
/**
* Allow customers to upload files
*
* @package Wordpress
* @subpackage Rightec Theme
* @author Dornaweb.com
*/
if ( current_user_can('customer') ) {
add_action('init', 'allow_customer_uploads', 20);
add_action('admin_init', 'allow_customer_uploads', 20);
}
function allow_customer_uploads() {
$customer = get_role('customer');
$customer->add_cap('upload_files');
$customer->add_cap('unfiltered_upload');
}
我也试过
"user role editor"
插件,但是还是不行
请帮帮我!
我在尝试允许新的 WooCommerce 客户根据订单上传文件时也遇到了这个问题。除了上述权限外,您还需要:
acf_form()数组中定义
'uploader' => 'basic'
。 'edit_pages'
和 'edit_posts'
到客户角色。您需要 ACF Pro 来支持基本上传器,这是您所需要的,因为除非您是管理员,否则 WP Media 上传器将永远不允许从前端上传。
希望这对某人有帮助!
我正在使用 ACF Pro 5.8.0,我已经使用下面的这个功能为作者角色添加了上限,并定义了“上传者”=>“基本”或“上传者”=>“wp”,但作者仍然无法在前端上传.
function wp_add_upload_files_cap() {
$role = get_role( 'author' ); //The role you want to grant the capability
$role->add_cap( 'upload_files' );
$role->add_cap( 'edit_pages' );
$role->add_cap( 'edit_posts' );
}
register_activation_hook( __FILE__, 'wp_add_upload_files_cap' );
upload_files
是我为实现此功能而需要添加的唯一功能。请参阅第一个答案中的@toni_lehtimaki 评论。
最近遇到了同样的问题,找到了这篇文章,现在找到了解决方案。所需的功能是
upload_files
以支持 WP 媒体上传器而不是基本的上传字段,并且需要功能 edit_published_pages
以修复权限限制“您无权将文件附加到此帖子”。 '
function customer_file_upload_permissions() {
$user = wp_get_current_user();
// If user is customer
if (in_array('customer', (array) $user->roles)) {
// If user can't upload files
if (!current_user_can('upload_files') || !current_user_can('edit_published_pages')) {
// Grant permission for file uploads for customer user role
$customer = get_role('customer');
// required in order to upload images via wp media --> acf_form 'uploader' => 'wp' support, instead of 'basic'
$customer->add_cap('upload_files');
// Fix error: You don't have permission to attach files to this post.
// https://support.advancedcustomfields.com/forums/topic/permission-issue-on-frontend-image-upload/
$customer->add_cap('edit_published_pages');
}
}
}
add_action('init', 'customer_file_upload_permissions');
解决方案很简单。为用户提供这些功能:
$author->add_cap('manage_options');