Skip to content

Instantly share code, notes, and snippets.

@lmartins
Created November 14, 2014 12:44
Show Gist options
  • Save lmartins/72a8bab3278ab19c1f35 to your computer and use it in GitHub Desktop.
Save lmartins/72a8bab3278ab19c1f35 to your computer and use it in GitHub Desktop.
Sanitize file names during upload to Wordpress
/**
* 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