0

I am still getting "X.epub: Sorry, this file type is not permitted for security reasons" despite adding:

define('ALLOW_UNFILTERED_UPLOADS', true);

to my wp-config.php.

Of course, I have allowed this type of file in my blog network's configuration:

enter image description here

Is this a normal situation (and using filters is the only workaround)?

Or this is something weird (like some plugin or theme overriding this) and you should keep looking for a possible cause?

EDIT (after comments and some more testing): This is .epub files-related only issue. I was able to verify that ALLOW_UNFILTERED_UPLOADS is working. The thing is that when it is enabled, it passes through all but .epub files. So, for the above screenshot, I was able to upload .azw3 and .mobi files. Out of all listed in "Upload file types" above only uploading of .epub files fails.

EDIT: This is my private blog network and I am logging via a super user account when using it.

4
  • 1
    If this is a Multisite installation (I think it is, judging by your mention of "network configuration"), then ALLOW_UNFILTERED_UPLOADS is disabled for non-super admins. This is by design.
    – Pat J
    Commented May 7, 2021 at 23:46
  • Thanks, but this isn't an issue here. I am a super user and ALLOW_UNFLITERED_UPLOADS works just fine. It is just that I am unable to upload .epub files only. Please, see an updated question. Thank you.
    – trejder
    Commented May 8, 2021 at 15:33
  • You may need to verify that WordPress is using the correct MIME type for .epub files -- from what I'm reading, it should be application/epub+zip. If it's not set, or if it's set incorrectly, you'll probably need to filter it so it uses the correct type.
    – Pat J
    Commented May 8, 2021 at 15:47
  • @PatJ I haven't got chance to try this (I must admit that I don't know where and what to look for), but from Robert Went's answer below it seems that this is a bug in Wordpress. I recall some forum talks from 2+ years before that this was not working and "now" it is working, so maybe a regression?
    – trejder
    Commented May 9, 2021 at 19:50

1 Answer 1

1

You probably need to allow the mime types for them to be allowed to upload.

https://www.robertwent.com/blog/adding-custom-mime-types-for-wordpress-uploads/

//The following goes in a themes functions file or a custom hooks plugin

function so_387865_custom_upload_mimes ( $existing_mimes ) {
    $existing_mimes['epub'] = 'application/epub+zip';
    $existing_mimes['mobi'] = 'application/x-mobipocket-ebook';
 
    return $existing_mimes;
}
 
add_filter('upload_mimes', 'so_387865_custom_upload_mimes');
6
  • Thanks, but this isn't an issue here, so I can only upvote your answer. I cannot accept it, since it doesn't resolve the issue.. The ALLOW_UNFLITERED_UPLOADS works just fine. It is just that I am unable to upload .epub files only. So you code won't change much, because I can already (even without this extra code) uplaod .mobi files. It's just the .epub files only that I have problem with. Please, see an updated question. Thank you.
    – trejder
    Commented May 8, 2021 at 15:34
  • 2
    I just tested on my local multisite install. After adding epub and mobi to the network settings, I still couldn't upload either even with ALLOW_UNFILTERED_UPLOADS set to true. When I use the code in my answer I can upload both without issues. Did you try it? Commented May 8, 2021 at 19:31
  • I haven't got chance to try it, because I still haven't figured out where would be the best place to put this code? If I put it into theme, this will work only for that single page of my blog network, which uses this theme. And this will be overwritten by next theme update. If I'd like to make this "update-save" and "network-wide", I'd probably have to put this into some separate plugin. Where did you tested your code?
    – trejder
    Commented May 9, 2021 at 19:51
  • I tested it as a must-use plugin. A single file added to /wp-content/mu-plugins/ (If the directory doesn't exist just create it). gist.github.com/robwent/71706cf29e302489a7ccb16b98f7ad99 Commented May 10, 2021 at 11:16
  • Works like a charm! 100 Kudos for you! For solving this problem and for teaching me basics about must-use plugins. Never heard of them. Seems like a quick solution for smallest pains. Thank you.
    – trejder
    Commented May 10, 2021 at 15:39

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.