How to enable file upload function for contributors using PHP function in WordPress

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

 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.a2hosting.com/blog/wordpress-child-theme/  

Follow the steps below to edit your Theme setting file to enable media tab for WordPress contributors:

  1. Log in to your WordPress site with an administrator account.
  2. On the Dashboard in the left sidebar, click Appearance, and then click Theme Editor:

  3. On the Theme Editor , select the Theme you want to edit from the dropdown:
  4. The files for this selected theme are listed on the right column under Theme Files. Click on the file named “functions.php”:

    1. 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'); 
      } 

       

  5. Click on the Update file button to save your changes to the functions.php file. 
  6. Before : Media option is not available for contributor

  7. After inserting the script: Contributor has the Media option to upload files:

Get Managed WordPress Hosting

Article Details

Other Articles in This Category

Show More

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

Usamos cookies con el fin de personalizar para usted nuestro sitio Web y analizar el uso de éste. Usted acepta esto haciendo clic en “Acepto” o al continuar usando el sitio Web. Hay más información sobre cookies en nuestra política de privacidad.