Enabling file upload function for contributors using PHP function in WordPress
Learn how to allow contributors to upload files using the media menu in WordPress. This article shows you how to add the Media tab for contributors with a PHP code.
WordPress, by default, does not allow contributors files to the site. WordPress contributors do not have the media tab on the dashboard to add any media files to the library. This article shows you how to add a media tab and allow contributors on your WordPress site to upload files using a simple PHP code snippet.
Enable media tab for contributors in WordPress
Important
Always perform a backup before you make any changes to the theme files. If you break any codes, it will be easier to revert your site to its last good known state. Alternatively, you could also create a child theme. Read this link on how to create a child theme: https://www.hosting.com/blog/wordpress-child-theme/
Follow the steps below to edit your Theme setting file to enable media tab for WordPress contributors:
-
Log in to your WordPress site with an administrator account.
-
On the Dashboard in the left sidebar, click Appearance, and then click Theme Editor:
-
On the Theme Editor, select the Theme you want to edit from the dropdown:
-
The files for this selected theme are listed on the right column under Theme Files. Click on the file named "functions.php":
-
Insert the following code to the end of functions.php file and click on Update to save the changes:
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');
}
-
Click on the Update file button to save your changes to the functions.php file.
-
Before: Media option is not available for contributor
-
After inserting the script: Contributor has the Media option to upload files:
Related Articles
Updated 3 days ago