Created
December 21, 2016 12:45
-
-
Save pedrorvidal/2d1677afc216f4932f7a1b2069aaae1a to your computer and use it in GitHub Desktop.
Upload arquivos acentuados WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // https://wordpress.org/support/topic/uploaded-image-with-accents-in-name-image-dont-show-in-safari-6 | |
| function sanitize_filename_on_upload($filename) { | |
| $ext = end(explode('.', $filename)); | |
| // Replace all weird characters | |
| $sanitized = preg_replace('/[^a-zA-Z0-9-_.]/', '', substr($filename, 0, -(strlen($ext)+1))); | |
| // Replace dots inside filename | |
| $sanitized = str_replace('.', '-', $sanitized); | |
| return strtolower($sanitized.'.'.$ext); | |
| } | |
| add_filter('sanitize_file_name', 'sanitize_filename_on_upload', 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment