Created
April 17, 2018 18:53
-
-
Save hawkidoki/c4aa28228802d7571a31c450de6172db to your computer and use it in GitHub Desktop.
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
<?php | |
add_filter('sanitize_file_name', 'hwk_sanitize_file_name'); | |
function hwk_sanitize_file_name($input){ | |
$path = pathinfo($input); | |
$extension = (isset($path['extension']) && !empty($path['extension'])) ? $path['extension'] : ''; | |
$file = (!empty($extension)) ? preg_replace('/.' . $extension . '$/', '', $input) : $input; | |
return sanitize_title(str_replace('_', '-', $file)) . ((!empty($extension)) ? '.' . $extension : ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment