lmartins
11/14/2014 - 12:44 PM

Sanitize file names during upload to Wordpress

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);