Last active
September 12, 2017 16:32
-
-
Save gbyat/35b28438952a7392354aed5ae9cc0316 to your computer and use it in GitHub Desktop.
Sanitize File Names like Titles in 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
<?php | |
/* | |
Plugin Name: Sanitize File Names | |
Description: extend file name sanitization | |
Author: Gabriele Lässer | |
Version: 1.0 | |
*/ | |
function pppf_extend_filename_sanitization( $title ) { | |
if ( seems_utf8( $title ) ) { | |
$chars[ chr(195).chr(132) ] = 'Ae'; | |
$chars[ chr(195).chr(164) ] = 'ae'; | |
$chars[ chr(195).chr(150) ] = 'Oe'; | |
$chars[ chr(195).chr(182) ] = 'oe'; | |
$chars[ chr(195).chr(156) ] = 'Ue'; | |
$chars[ chr(195).chr(188) ] = 'ue'; | |
$chars[ chr(195).chr(159) ] = 'ss'; | |
$chars[ chr(195).chr(134) ] = 'Ae'; | |
$chars[ chr(195).chr(166) ] = 'ae'; | |
$chars[ chr(195).chr(152) ] = 'Oe'; | |
$chars[ chr(195).chr(184) ] = 'oe'; | |
$chars[ chr(195).chr(133) ] = 'Aa'; | |
$chars[ chr(195).chr(165) ] = 'aa'; | |
$title = strtr( $title, $chars ); | |
} | |
return strtolower( remove_accents( $title ) ); | |
} | |
add_filter( 'sanitize_file_name', 'pppf_extend_filename_sanitization' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment