I Have plugin called MyPlugin written by me. i have a yes or no radio button , If the option is yes means it should allow contributor to upload image and no means it should not allow.
This is the code to allow contributor to upload image
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');
}
i need a help where should i put this code in the plugin, i tried it but i got error as
Error in wp-includes/capabilities.php on line 1059
You are calling functions that can’t be called before init(), so they are undefined (specifically, wp_get_current_user() is defined in wp-includes/pluggable.php and that isn’t loaded until after all plugins have been loaded). You need to rearrange your code to check user privileges after admin_init is called, e.g.
NB: just solving your error problem here, have not looked at the logic of what you’re doing!