Are you looking for a way to allow your users with contributor user role to upload files? While there’s probably a plugin for this, we have created a quick code snippet that you can use to let contributors upload files in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
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'); }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes and how to set up author tracking in WordPress with Google Analytics.
Hey Kevin,
This is brilliant & works perfectly. Thanks for saving me the need to get a plug in =)