How to allow contributors to add images in WordPress?

Started by Turkey, January 15, 2018, 04:42:18 PM

Previous topic - Next topic

Turkey

In WordPress the user "contributor" can add content but cannot upload images using "add media" button. To allow such users to add images, add the below snippet in your themes functions.php file. You can add the code at the end of the file before the tag ?>



//Allow Contributors to Add Media Start
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');
}
//Allow Contributors to Add Media End

█ MilesWeb - Your Hosting, Our Responsibility!
Web Hosting @ ₹60/mo
Servers in India, UK, US, Canada, Australia, Singapore Datacenter