投稿中:contributor
在functions.php文件添加以下代码:
if ( current_user_can('subscriber') && !current_user_can('upload_files') )
add_action('init', 'allow_subscriber_uploads');
function allow_subscriber_uploads() {
$subscriber = get_role('subscriber');
$subscriber->add_cap('upload_files');
}
订阅者:subscriber
在functions.php文件添加以下代码:
if ( current_user_can('subscriber') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
$contributor = get_role('subscriber');
$contributor->add_cap('upload_files');
}
上述代码执行过一次后,投稿者的权限设置将储存到数据库中,即使你移除以上代码,投稿者也依然拥有上传文件的权限。如果你想剥夺投稿者上传文件的权限,你可以使用以下代码来替换上面的代码:
if ( current_user_can('contributor') && current_user_can('upload_files') ) add_action('admin_init', 'allow_contributor_uploads'); function allow_contributor_uploads() { $contributor = get_role('contributor'); $contributor->remove_cap('upload_files'); }