Prevent renaming of uploaded media

“despite the fact that it’s just not necessary” I think you’d be surprised by how unnecessary looking stuff has a tendency of becoming absolutely necessary on some poorly configured servers. Else yes, it can be overridden using filters. You’re looking into overriding the stuff in sanitize_file_name(), which is located in wp-includes/formatting.php.

Need to download uploaded binary file

If your webserver is Apache, you’ll need to tell apache what kind of mime type your file is, so Apache knows how to handle it. You should be able to use the “application/octet-stream” mime type in your .htaccess, in order for Apache to force a download. Learn more here: http://www.htaccess-guide.com/adding-mime-types/ (see the 3rd paragraph, starting … Read more

Conditional add_filter for upload directory?

I know it’s been a while, but I wanted to offer a solution, if only for those who come across this question via Google. The issue is with the order of the parameters in the query string when you build the URL for the media uploader. My experience is that any parameters that come after … Read more

How can I reduce file upload size?

Absolutely, you can simply hook into upload_size_limit and set a maximum filesize: // Change the upload size to 1MB add_filter( ‘upload_size_limit’, ‘wpse_163236_change_upload_size’ ); function wpse_163236_change_upload_size() { return 1000 * 1024; }

media_handle_upload : undefined function?

So I dont know if its the best way but my problem was the if statement surrounding the require_once on the necessary files that contain the function. Commented out the IF statement and it did the trick. I’ll go have that coffee now 😉 //if (!function_exists(‘wp_generate_attachment_metadata’)){ require_once(ABSPATH . ‘wp-admin/includes/image.php’); require_once(ABSPATH . ‘wp-admin/includes/file.php’); require_once(ABSPATH . ‘wp-admin/includes/media.php’); … Read more

Why does SVG upload in Media Library fail if the file does not have an XML tag at the beginning?

It seems that in the recent releases of WordPress, changes were made to the mime type handling to make sure that files have the extension they say they do: https://make.wordpress.org/core/2018/12/13/backwards-compatibility-breaks-in-5-0-1/ This poses an issue for SVG files without the tag in them. SVG is actually an XML, and WordPress is now requiring to have a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)