| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Replace icelandic. |
|---|
| 4 | Description: Replaces icelandic letters like æ, þ, ð, í and other letters from uploaded files names. |
|---|
| 5 | Version: 1.0 |
|---|
| 6 | Author: Vilhjálmur Valgeirsson |
|---|
| 7 | Author URI: http://www.valgeirsson.is |
|---|
| 8 | */ |
|---|
| 9 | function replace_icelandic($str) { |
|---|
| 10 | $icelandic = array("á", "Á", "ð", "é", "É", "í", "Í", "ó", "Ó", "ú", "Ú", "ý", "Ý", "þ", "Þ", "æ", "Æ", "ö", "Ö"); |
|---|
| 11 | $replacement = array("a", "A", "d", "e", "E", "i", "I", "o", "O", "u", "U", "y", "Y", "th", "TH", "ae", "AE", "o", "O"); |
|---|
| 12 | |
|---|
| 13 | return str_replace($icelandic, $replacement, $str); |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | function nonicelandic_file_name( $file ) { |
|---|
| 17 | $file['name'] = replace_icelandic(utf8_decode($file['name'])); |
|---|
| 18 | |
|---|
| 19 | return $file; |
|---|
| 20 | } |
|---|
| 21 | add_filter( 'wp_handle_upload_prefilter', 'nonicelandic_file_name', 15 ); |
|---|
| 22 | |
|---|
| 23 | ?> |
|---|