Allow Contributors to Upload Media
Lets users who can write posts but not upload files (the Contributor role) add images to their drafts. The role itself is not changed in the database.
Opens WPIDE on
Code
add_filter( 'user_has_cap', function ( $allcaps ) {
if ( ! empty( $allcaps['edit_posts'] ) && empty( $allcaps['upload_files'] ) ) {
$allcaps['upload_files'] = true;
}
return $allcaps;
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.