source: trunk/www.guidonia.net/wp/wp-content/plugins/sanitize-with-undescores/1.0/sanitize_with_undescores.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 1.4 KB
Line 
1<?php
2/*
3Plugin Name: Sanitize permalink with undescores
4Plugin URI: http://www.melodycode.com
5Description: Modifica il permalink affinch&egrave; ogni parola sia separata da un underscore "_" al posto del trattino "-" che Wordpress usa di default (si tratta solo di una leggera modifica alla funzione gi&agrave; esistente).
6Version: 1
7Author: Daniele Simonin
8Author URI: http://www.melodycode.com
9*/
10
11function sanitize_permalink_with_undescores($title) {
12 $title = strip_tags($title);
13 // Preserve escaped octets.
14 $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
15 // Remove percent signs that are not part of an octet.
16 $title = str_replace('%', '', $title);
17 // Restore octets.
18 $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
19
20 $title = remove_accents($title);
21 if (seems_utf8($title)) {
22 if (function_exists('mb_strtolower')) {
23 $title = mb_strtolower($title, 'UTF-8');
24 }
25 $title = utf8_uri_encode($title);
26 }
27
28 $title = strtolower($title);
29 $title = preg_replace('/&.+?;/', '', $title); // kill entities
30 $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
31 $title = preg_replace('/\s+/', '_', $title);
32 $title = preg_replace('|_+|', '_', $title);
33 $title = trim($title, '_');
34
35 return $title;
36}
37
38remove_action('sanitize_title', 'sanitize_title_with_dashes');
39add_action('sanitize_title', 'sanitize_permalink_with_undescores');
40?>
Note: See TracBrowser for help on using the repository browser.