Code Snippets

Allow User to Upload Images – PHP Code Snippet

Riz Ali
Riz
Jul 29, 2019
1 min read
104 words

In WordPress theme there’s no option for contributes to upload images. In fact, WordPress doesn’t allow users to do so until you give them privilege. You’ll have to make them Editor or Author so images can be uploaded by them but code snippet facilitate Allow User to Upload Images. They don’t even need any additional privileges.

Permit User to Upload Images – PHP Code Snippet

Paste it in the functions.php file of your theme.

if ( current_user_can('contributor') && !current_user_can('upload_files') )
     add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
     $contributor = get_role('contributor');
     $contributor->add_cap('upload_files');
}
Riz Ali

Riz

Author

Riz is a Senior Web Strategist with over 14+ years of hands-on experience in full-stack web design and digital architecture. Having successfully delivered 250+ web projects, he believes passion is the engine of innovation. Riz specializes in translating complex technical concepts into accessible, fanatical content, helping businesses bridge the gap between aesthetic design and high-performance engineering. His work has been instrumental in scaling digital presence for startups and established brands alike.

View all posts

Continue reading

You might also like

Leave a Reply

Your email address will not be published. Required fields are marked *

Menu