In WordPress by default the Add Media functionality (called Capability in wordpress terms) is disabled for users with Contributor role. If you are hosting multiuser wordpress site where users with contributor roles logs in and update their post, they would not be able to add images / medias. That’s quite annoying. The user who is editing a post must be able to add supported media for their post.
Check below screenshot. The current user has “Contributor” role. Hence she is not able to view Add media button.
Now to overcome this there is a simple trick. By using WordPress’s add_cap method we can add different capabilities to user. So we can add upload_files capability to a Contributor using this method.
Add following code in functions.php file of your current wordpress theme.
// Allow Contributors to Add Media
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');
}
Code language: PHP (php)
Now logout and login again using a user with contributor role. Ta’da.. Add media button is visible now.
Use this simple trick to make Add media button visible for contributors on your wordpress site. I think this simple trick will help those who have contributors on their site.
Where are you man? After long time?
Hi Gaurav, Ya long time :-) will call you soon.. Thanks for the comment.
Thanks for Sharing the Information.
Thanks a lot for this, it was super simple!
Worked like a charm! Thanks for the knowledge and for taking the time to make the post.
W 10,
WP Version: 4.4.1
WPMU: No
MySQL Version: 5.6.26
PHP Version: 5.5.30
WP URL: http://localhost/wordpress
plugins :
All In One WP Security 4.0.3
Contact Form 7 4.3.1 http://contactform7.com/
Disable Password Reset 1.0
Really Simple CAPTCHA
I put that code in a plugin and I caught an issue and that comment :
Fatal error:call to undefined function wp_get_current_user() in \wp-includes\capabilities.php on line 424
I code in a local environment and that code put in functions.php works fine.
This code is no good — current_user_can(‘contributor’) is not valid, you need to add a capability, not a role name.
Better off using a plugin like https://wordpress.org/plugins/capability-manager-enhanced/
Wow…Work perfectly for me, thanks mate…
Users with Contributor role – always face this issue. Usually my customers do.
Well caught and solved.
very interesting tips … awaited next article :)
this work perfectly ……thank you man
Thanks it worked
Really informative article.Thanks for sharing it.