Created
November 14, 2014 12:44
-
-
Save lmartins/72a8bab3278ab19c1f35 to your computer and use it in GitHub Desktop.
Sanitize file names during upload to Wordpress
This file contains 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
/** | |
* Sanitize File name during upload | |
* http://stackoverflow.com/questions/3259696/rename-files-during-upload-within-wordpress-backend | |
*/ | |
function make_filename_hash($filename) { | |
$info = pathinfo($filename); | |
$ext = empty($info['extension']) ? '' : '.' . $info['extension']; | |
$name = basename($filename, $ext); | |
return md5($name) . $ext; | |
} | |
add_filter('sanitize_file_name', 'make_filename_hash', 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment