有时候我们需要网站前端让用户上传图片,可是wordpress默认的只有编辑权限才能在前端上传,但是一般默认的用户权限是订阅者或者投稿者,所以得改改他们的权限,代码如下:
function MBT_enable_file_uploads_by_role( ) {
$role = 'subscriber';//这是角色
if(!current_user_can($role) || current_user_can('upload_files'))
return;
$contributor = get_role( $role );
$contributor->add_cap('upload_files');
} add_action('admin_init', 'MBT_enable_file_uploads_by_role');


0 个评论