I am working on a clients site, one of the features they want is for his Editors or Authors to only be able to select existing images to insert into Posts from the Media Library.
So looking at the media manager/upload screen below, is it possible to make the Upload Files
tab to only be visible to Admin Users
and also to make the Media Library
shown by Default when this Dialog is shown?
Here are 2 methods to disable all uploading for users that are not administrators:
Method 1:
Remove the
upload_files
capability from the roles you do not want to be able to upload.e.g. removing it from author role:
This is saved to the database so it should only happen once, not on every page load. Removing it from the editor role should be the same albeit with the obvious modification.
Removing the capability will have the desired effect, but it may have additional effects you may not find so desirable, the only way to be sure is to test
Method 2
Consider this code. It uses the
wp_handle_upload_prefilter
filter to check the user has admin status, and aborts the upload if they do not. It relies on only administrators and above havingmanage_options
.You can make use of this filter to be more specific than upload_file, e.g. preventing the upload of images, and only images, but allowing audio, etc