Skip to content

Instantly share code, notes, and snippets.

@LanF3usT
Forked from theamnesic/sunnytize.php
Created November 28, 2011 15:40
Show Gist options
  • Save LanF3usT/1400817 to your computer and use it in GitHub Desktop.
Save LanF3usT/1400817 to your computer and use it in GitHub Desktop.
WordPress plugin that removes evil characters in file names
<?php
/*
Plugin Name: Sunnytize
Plugin URI:
Description: A better file name sanitizer
Version: 1.0
Author: Sunny Ripert
Author URI: http://sunfox.org
*/
function sunnytize_file_name_chars($special_chars, $filename_raw = '') {
return array_merge($special_chars, str_split('éè’ààäçéèêöôùûü£€%@+«»°'));
}
add_filter('sanitize_file_name_chars', 'sunnytize_file_name_chars');
function sunnytize_file_name($filename, $filename_raw = '') {
return strtolower($filename);
}
add_filter('sanitize_file_name', 'sunnytize_file_name');
function sunnytize_slug($slug) {
return preg_replace('/[^a-z0-9-_]/', '', $slug);
}
add_filter('editable_slug', 'sunnytize_slug');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment