Tagged: Limit New Media
- This topic has 6 replies, 2 voices, and was last updated 9 years, 4 months ago by Syam Mohan.
-
AuthorPosts
-
August 11, 2015 at 1:01 pm #14239Steve kelseyParticipant
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 #14248Syam MohanKeymasterHi 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 #14307Steve kelseyParticipantHi 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 #14317Syam MohanKeymasterfunction 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 #14775Syam MohanKeymasterHi Steve,
Does the code work?
Thanks
Syam
August 24, 2015 at 1:30 pm #15030Steve kelseyParticipantWe 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 #15035Syam MohanKeymasterHi 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
-
AuthorPosts
- The topic ‘Role needs to permit View and Use of Library Media – But NOT Add New Media’ is closed to new replies.