0

I am looking for a way to disable sanitize_file_name function without modifying the functions.php or formatting.php. I am uploading files that have other language file names and all I am getting are dashes right now.

I found out how to remedy this, but it is by commenting a line out in the functions.php and I do not want to do that. Here is the line that I am talking about: (starting on line 1856 of functions.php)

function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
    // Sanitize the file name before we begin processing.
    $filename = sanitize_file_name($filename); <--- If I comment this out, it works like I want.

I am sure that I can apply a filter of some sorts, but I have never used filters and would be interested in learning. I looked at the Codex, but it did not make sense to me.

1

Can you try adding the following code to the functions.php file in your theme directory and see if works for you

function keep_raw_filename( $filename, $filename_raw )
{
    return $filename_raw;
}

add_filter( 'sanitize_file_name', 'keep_raw_filename', 10, 2 );
  • 1
    That will do the trick, but be aware that this may not necessarily be safe. If people can upload files to your site with arbitrary filenames, then there is a chance of bad-things-happening. – Otto Oct 29 '14 at 18:59
  • @czerspalace Unfortunately, that did not work. It is still adding the dashes to the file name instead of the language characters that I need. – dericcain Oct 29 '14 at 19:40
  • @czerspalace Do you have another recommendation? For some reason, the above answer is not working. Could it be the priority? – dericcain Oct 31 '14 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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