Skip to content

Instantly share code, notes, and snippets.

@gbyat
Last active September 12, 2017 16:32
Show Gist options
  • Save gbyat/35b28438952a7392354aed5ae9cc0316 to your computer and use it in GitHub Desktop.
Save gbyat/35b28438952a7392354aed5ae9cc0316 to your computer and use it in GitHub Desktop.
Sanitize File Names like Titles in WordPress
<?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