1 | <?php
|
---|
2 | /*
|
---|
3 | Plugin Name: Sanitize permalink with undescores
|
---|
4 | Plugin URI: http://www.melodycode.com
|
---|
5 | Description: Modifica il permalink affinchè 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à esistente).
|
---|
6 | Version: 1
|
---|
7 | Author: Daniele Simonin
|
---|
8 | Author URI: http://www.melodycode.com
|
---|
9 | */
|
---|
10 |
|
---|
11 | function 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 |
|
---|
38 | remove_action('sanitize_title', 'sanitize_title_with_dashes');
|
---|
39 | add_action('sanitize_title', 'sanitize_permalink_with_undescores');
|
---|
40 | ?> |
---|