10

I'm using Wordpress 3.4.2 for a private blog, i.e. one on which only I can post. Now, Wordpress prevents me from uploading certain file types (like C# source files). As far as I understand it, there's a white-list that defines what can be uploaded.

Is there a plugin that can extend - or better, even disable - this white-list?

All other answers tell me I should edit my theme but I'd rather have a plugin for that (so that I don't need to edit all my themes).

Also, I found this plugin but, again, it requires me to edit some file on my server (that's probably overwritten when the plugin is updated).

So, is there anything else?

1
  • Open your website via FTP, create a folder called "Uploads" or something like this and put your files in there. Then link to them. That's it!
    – IceCold
    Commented Aug 7 at 9:13

3 Answers 3

13

You can create a plugin or add this to the config file, but for 3.9.2 this worked for me.

define('ALLOW_UNFILTERED_UPLOADS', true);
6
  • This is the Core way of doing it. +1 Commented Dec 22, 2014 at 20:30
  • 2
    Confirmed to work in Wordpress 4.1 as well!
    – Joel Purra
    Commented Jan 14, 2015 at 13:46
  • This, in wp-config.php. I really don't understand why it isn't the default, at least for administrators. Commented Jun 2, 2016 at 20:19
  • Still it disallows me to upload, say, ".exe" files "for security reasons". (Can be my Real media library plugin issue?) Admin user. Allowing mime types specificly through upload_mimes filter works.
    – Fanky
    Commented Nov 10, 2020 at 14:47
  • What security implications are there for this? Does flicking this setting off leave my site vulnerable to malicious script uploads etc? Commented Dec 22, 2020 at 2:17
3

Filter 'user_has_cap' and set 'unfiltered_upload' to 1.

Sample code not tested:

/*
Plugin Name: Remove Uploads Filter
Plugin URI: http://wordpress.stackexchange.com/questions/67225/allow-all-file-types-for-upload
Description: Disables white-list filter for uploads
Version: 1.0
Author: WPSE - @toscho
*/

add_filter( 'user_has_cap', 'wpse_67225_unfiltered_upload' );

function wpse_67225_unfiltered_upload( $caps )
{
    $caps['unfiltered_upload'] = 1;
    return $caps;
}
1
  • I've tried this with WP 5.7.2, attempting to upload JSON files, and unfortunately it doesn't work.
    – clayRay
    Commented Jun 24, 2021 at 19:26
2

Unfortunately, toscho's answer doesn't work - at least not in Wordpress 3.4 and above.

The correct solution is the following:

#
# For this, see: wp-includes/capabilities.php > map_meta_cap()
#
function wpse_6533_map_unrestricted_upload_filter($caps, $cap) {
  if ($cap == 'unfiltered_upload') {
    $caps = array();
    $caps[] = $cap;
  }

  return $caps;
}

add_filter('map_meta_cap', 'wpse_6533_map_unrestricted_upload_filter', 0, 2);
5
  • Hi, where should I put the code above? Will it work if I put it on my functions.php? Commented Aug 4, 2016 at 9:36
  • @LeonardDrapeza Yes, you can put it in functions.php of your theme. But then, this will only work as long as your theme is active AFAIK. Commented Aug 4, 2016 at 9:39
  • 1
    This doesn't work either. Commented Feb 23, 2017 at 13:20
  • Still it disallows me to upload, say, ".exe" files "for security reasons". (Can be my Real media library plugin issue?) Admin user. Allowing mime types specificly through upload_mimes filter works.
    – Fanky
    Commented Nov 10, 2020 at 14:47
  • I've tried this with WP 5.7.2, attempting to upload JSON files, and unfortunately it doesn't work.
    – clayRay
    Commented Jun 24, 2021 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.