Forked from onnimonni/remove-accents-on-upload.php
Created
February 25, 2016 17:43
-
-
Save k1sul1/eb829ee12d8a8c6d1b30 to your computer and use it in GitHub Desktop.
Wordpress plugin which sanitizes files on upload. This fixes OS-X NFD characters as well if you have Normalizer class and icu library installed.
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: Remove accents from files on upload | |
* Plugin URI: https://gist.github.com/onnimonni/d58bdcff44f8208a15c7 | |
* Description: Sanitize accents from Cyrillic, German, French, Polish, Spanish, Hungarian, Czech, Greek, Swedish during upload. Also fix OS-X NFD filenames. | |
* Version: 1.0 | |
* Author: Onni Hakala | |
* Author URI: http://github.com/onnimonni | |
* License: GPLv3 | |
*/ | |
if( ! function_exists( 'onnimonni_sanitize_filenames_on_upload' ) ) : | |
function onnimonni_sanitize_filenames_on_upload( $filename ) { | |
// Normalize NFD characters if possible | |
if(class_exists('Normalizer')) { | |
$filename = Normalizer::normalize($filename); | |
} | |
// Remove accents | |
$filename = remove_accents($filename); | |
// filename to lowercase for better urls | |
return strtolower( $filename ); | |
} | |
add_filter( 'sanitize_file_name', 'onnimonni_sanitize_filenames_on_upload', 10 ); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment