HomeBLOGGING

Learn How To Activate Media Button For Contributors

Learn How To Activate Media Button For Contributors
Like Tweet Pin it Share Share Email

Do you own a wordpress website/blog with multiple authors or multiple contributors/guest authors? If yes, then you might want to know how to activate media button for contributors or other authors so that they can upload files, images while drafting a post in WordPress?

Also Read: 50 WordPress Premium Themes in Just $49.50(Limited Time Offer)

Why you manually need to Enable Media Button For Contributors?

You need this because in WordPress “the Contributors” can’t upload any media from the dashboard.  Meaning – they can write a post but cannot upload their own media (images, video, PDFs, etc.) while writing. That’s the default WordPress rule.

Because of this rule, it’s time-consuming for the editor to assemble the post with images and publish it. To make it easier for those writing content on your blog and those editing it, it might be easier to change this default rule and let your writers add their own media to their posts.

Check below screenshot. The current user has “Contributor” role. You can see that the person is not able to view Add media button.

wordpress-contributor-add-media-disabled

Hot Deal: Start A Blog Today in Just $2.65 At Bluehost & Get A FREE Domain

How To Activate Media Button For Contributors With Full Access To Media Library

To add a capability to a role or a specific user in WordPress, we can make use of add_cap method/function.

By using WordPress’s add_cap method we can add different capabilities to the user.

So with the help of this method, we can add the upload_files capability to a Contributor.

To activate media button for contributor role in WordPress, add the below code in functions.php file of your current wordpress theme and save the file.

“Notice that the code below will add capabilities for contributor role to upload new media but would also allow them to see the existing media added by other user roles like other contributors, authors, admin etc. “

//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');
}


Now logout and login again using the user with contributor role.

TA’DAA.. Add media button is visible now. See below:

wordpress-contributor-activate-media-button-visible

How To Activate Media Button For Contributors With Limited Access To Media Library

As a multi-author or contributor site owner, we probably want to limit the access of media library for individual roles.

The best we can do it to show the user only the media they have uploaded using their account. They should not see the media/images/docs etc added by other contributors. Right?

If you want to enable this functionality for the contributors on your WordPress site then add the below code in functions.php file of your current wordpress theme and save the file.

/**
 * Allow access to own content only
 */
function my_authored_content($query) {

//get current user info to see if they are allowed to access ANY posts and pages
$current_user = wp_get_current_user();
// set current user to $is_user
$is_user = $current_user->user_login;

//if is admin or 'is_user' does not equal #username
if (!current_user_can('manage_options')){
    //if in the admin panel
    if($query->is_admin) {

        global $user_ID;
        $query->set('author',  $user_ID);

    }
    return $query;
}
return $query;
}
add_filter('pre_get_posts', 'my_authored_content');

With the above code, your WordPress site will only let admin see the media library content. You can either add it to the main functions file or turn this code into a plugin.

To create a plugin of the above functionality, follow these steps:

  • Create a new text file and save the file as user-content-only.php
  • Copy & Paste the below code into the file:
<?php
/*
	Plugin Name: User Content Only Content
	Version: 1.0
	Plugin URI: https://digitalharpreet.com/ 
	Description: Only shows content for user(author) of the content and admins.
	Author: https://DigitalHarpreet.Com
	Author URI: https://digitalharpreet.com/ 
*/

/**
 * Allow access to own content only
 */
function user_content_only($query) {

//get current user info to see if they are allowed to access ANY posts and pages
$current_user = wp_get_current_user();
// set current user to $is_user
$is_user = $current_user->user_login;

//if is admin or 'is_user' does not equal #username
if (!current_user_can('manage_options')){
    //if in the admin panel
    if($query->is_admin) {

        global $user_ID;
        $query->set('author',  $user_ID);

    }
    return $query;
}
return $query;
}
add_filter('pre_get_posts', 'user_content_only');

?>
  • Save the file and the upload the php file to your plugins directory.

That’s it. Ask your contributor to re-login to the dashboard so that he finds the upload image button right in place.

Other ways: Allow Contributors To Upload Images Using WordPress Plugins

1) User Role Editor

User Role Editor is a very simple plugin that makes it easy to manage user role and capabilities in WordPress.

With User Role Editor WordPress plugin you can change user role (except Administrator) capabilities easy, with a few clicks.

User-Roles-WordPress-Plugin-Activate-Media=Button-For-Contributors-activate media button

Just turn on check boxes of capabilities you wish to add to the selected role and click “Update” button to save your changes. That’s done.

User-Role-Editor-settings-screenshot-activate media button

Add new roles and customize its capabilities according to your needs, from scratch or as a copy of another existing role.

HOT DEAL: Get A Free WordPress Theme: Read More Here

User Reviews:

wordpress-contributor-add-media-user-roles-plugins-reviews-activate media button

Conclusion:

The result of all three methods will allow your contributors to Add Media using the Media Button from their WordPress dashboard to their own blog posts. If the plugin doesn’t limit the media library access to their own stuff then you can always add the above code to allow them to see media added my them only. Share this with others if you like this article. Thanks for reading.

Hosting Deals & Coupons: 

30% OFF in Domains Coupon

25% OFF InMotion Shared Hosting

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × four =

This site uses Akismet to reduce spam. Learn how your comment data is processed.