Restricting media upload within a role

Hi everyone

I'd like to restrict a role in WordPress, possibly the contributor role (but as yet undecided) from uploading media - principally images - to a site. I've looked at plugins such as User Role Editor and Adminize, but is there a more straightforward way of doing this?

Cheers, Tom

  • Patrick

    Hey there @Tom

    I hope you're having a great day!

    The problem with using a plugin like User Role Editor (which is fabulous in and of itself) is that it can only grant or restrict existing WordPress capabilities (either built-in ones, or ones created by other plugins or custom functions). It cannot modify those capabilities though the way you want.

    The ability to upload images is part of the upload_files capability. So is the ability to upload audio, video or any other filetype that you specify in your install.

    So you would need to write a custom function to filter that capability for a specified role. Fortunately, that's not very difficult. :slight_smile:

    See this post on our blog for a basic function, and be sure to check the comments for how you can adapt the function to restrict its execution only for a specified role:

    I hope this helps! And thanks for being a member :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.