我有我编写的名为 MyPlugin 的插件。我有一个是或否单选按钮,如果选项是是意味着它应该允许贡献者上传图片,而不是意味着它不应该允许。
这是允许贡献者上传图片的代码
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->add_cap('upload_files');
}
// this is the code to remove if the capabilities if it is added
if ( current_user_can('contributor') && current_user_can('upload_files') )
add_action('admin_init', 'remove_contributor_upload');
function remove_contributor_upload(){
$con = get_role('contributor');
$con->remove_cap('upload_files');
}
我需要帮助我应该把这段代码放在插件的哪里,我试过了,但我得到了错误
Error in wp-includes/capabilities.php on line 1059