How to Allow Contributors to Add Photos in WordPress

Home » Snippets » How to Allow Contributors to Add Photos in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

If you run a website that allows multiple authors or contributors, you may want to give them the ability to add photos to their posts. By default, WordPress limits this feature to users with editor or administrator roles. However, allowing contributors to add their own photos can help your site feel more collaborative and engaging. In this article, we’ll show you how to enable photo uploads for contributors in WordPress.

					function wpturbo_allow_contributors_to_upload_photos() {
    $contributor_role = get_role( 'contributor' );
    $contributor_role->add_cap( 'upload_files' );
    $contributor_role->add_cap( 'edit_published_posts' );
}
add_action( 'admin_init', 'wpturbo_allow_contributors_to_upload_photos' );
				

In this article, we will learn how to allow contributors to upload photos in WordPress. By default, contributors only have the ability to write and edit their own posts, but they cannot upload files like images.

To enable the ability for contributors to upload photos, we can use the code snippet provided above.

First, we create a new function called wpturbo_allow_contributors_to_upload_photos(). Inside this function, we get the contributor role object using the get_role() WordPress function. This function retrieves the role for the given role name.

Next, we use the add_cap() function to add two capabilities to the contributor role: upload_files and edit_published_posts. The first capability allows contributors to upload files to the WordPress media library, while the second allows them to edit their own published posts.

We use the add_action() function to hook our wpturbo_allow_contributors_to_upload_photos() function to the admin_init action. This ensures that our function is executed when the WordPress admin area is loaded.

With these modifications, contributors can now upload photos to the media library and use them in their own posts. This is a useful feature for blogs where users can contribute content but should not have full access to the WordPress backend.

Register an account to save your snippets or go Pro to get more features.