WPFront
  • Home
  • Plugins
    • Notification Bar Plugin
      • Plugin Ideas
      • Plugin Settings
      • Plugin FAQ
    • Scroll Top Plugin
      • Plugin Settings
      • Plugin FAQ
    • User Role Editor Plugin
      • Plugin Documentation
      • Plugin Settings
      • Plugin FAQ
    • Paddle Gateway Plugin
  • Go Pro
  • Support
    • Documentation
    • FAQ
  • Affiliates
  • Contact
  • Login
  • Cart

Tagged: Limit New Media

  • This topic has 6 replies, 2 voices, and was last updated 9 years, 8 months ago by Syam Mohan.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • August 11, 2015 at 1:01 pm #14239
    Steve kelsey
    Participant

    Need to permit a Contributor (new Contributor1 role created) to be able to access and use media in the library, but not be able to Add New media to the library. Turned off the “New” feature on the menu, which worked for the Toolbar Menu, but the Add new button still exists in the Library. Tried multiple settings and am able to get the “…not permitted …” message to come up if they click on the top “New -> Media” drop down, but the Add button in the Library, although has sometimes shown the same “not permitted” message (because it points to the exact same URL), 95% of the time it allows them to add a media asset. Running WPFront User Role Editor Business Pro on WordPress 4.2.2. Also running Enhanced Media Library plug-in.

    August 11, 2015 at 6:45 pm #14248
    Syam Mohan
    Keymaster

    Hi Steve,

    WordPress only checks on ‘upload_files’ to give upload permission. But that capability is also needed to give access to media library. As you said, you will be able to remove the “Add New” using menu editor, but the “Add New” within the Media Library uses ajax upload so it won’t be limited. So its not possible through the UI at this moment.

    I could give you a code snippet that you can add to your functions.php to limit the user from uploading files if you are comfortable with it.

    Thanks

    Syam

    August 12, 2015 at 10:26 am #14307
    Steve kelsey
    Participant

    Hi Syam,
    Yes, please send the code snippet to add to functions.php. We will give it a try.

    August 12, 2015 at 6:16 pm #14317
    Syam Mohan
    Keymaster
    
    
    
    function wpfront_custom_upload_prefilter( $file ) {
        $roles_not_allowed = array('author', 'editor'); //not allowed role names
    	
    	$user = wp_get_current_user();
    	
    	foreach($roles_not_allowed as $role) {
    		if(in_array($role, $user->roles)) {
    			$file['error'] = 'You are not allowed to upload.';
    			return $file;
    		}
    	}
    
        return $file;
    }
    add_filter( 'wp_handle_upload_prefilter', 'wpfront_custom_upload_prefilter' );
    

    The above code limits any user who belongs to Author or Editor from uploading. Make sure to change the role names to your role names.

    Thanks

    Syam

    August 19, 2015 at 11:14 pm #14775
    Syam Mohan
    Keymaster

    Hi Steve,

    Does the code work?

    Thanks

    Syam

    August 24, 2015 at 1:30 pm #15030
    Steve kelsey
    Participant

    We are still having problems with the “Add New” button that appears directly on the Media Library page. Using WPFront permissions and the Menu Editor, we were able to turn off most references to the Add New media. However, the button still exists on the Media Library page near the top. The code has not worked for us. Do you have any other suggestions? Many Thanks.

    August 24, 2015 at 5:13 pm #15035
    Syam Mohan
    Keymaster

    Hi Steve,

    To remove the ‘Add New’ button, you will have to remove the ‘upload_files’ capability. But that will disable the whole media library functionality, so you don’t want to do that.

    The code I sent you will not remove this button. But it will still block users from uploading files, they will see an error message when they try to upload.

    When you say its not working, what does exactly it mean? If you meant its not removing the button, that is the right behavior. It will not remove the button.

    Thanks

    Syam

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Role needs to permit View and Use of Library Media – But NOT Add New Media’ is closed to new replies.
Log In
Lost Password

Search Topics

Documentation

FAQ
Roles List Add Role Edit Role Delete Role Restore Role Add or Remove Capability Assign/Migrate Users Posts/Pages Extended Permissions Custom Post Type Permissions Navigation Menu Permissions Widget Permissions Admin Menu Editor Media/Attachment File Permissions User Level Permissions Content Restriction Shortcodes Login Redirect Export Roles Import Roles Bulk Edit Settings Multisite Roles List Multisite Add New Role Multisite Edit Role Multisite Delete Role Multisite Restore Role Multisite Sync Roles Multisite Settings WordPress Capabilities Actions and Filters Installation Instructions