/
comma-diacritics.php
107 lines (92 loc) · 3.39 KB
/
comma-diacritics.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/*
Plugin Name: Correct Romanian Diacritics
Plugin URI: https://github.com/stas/comma-diacritics
Description: Searches and replaces the wrong (sedilla) diacritics with the correct ones on data saving
Version: 0.3
Author: Stas Sușcov
Author URI: http://stas.nerd.ro/
*/
?>
<?php
/* Copyright 2010 Stas Sușcov <stas@nerd.ro>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
?>
<?php
define( 'COMMA_DIAS_VERSION', '0.3' );
/**
* comma_dias_get()
*
* Just a wrapper to generate the correct array of diacritics that are to be changed
* @return Array
*/
function comma_dias_get() {
return array(
'Ş' => 'Ș',
'ş' => 'ș',
'Ţ' => 'Ț',
'ţ' => 'ț'
);
}
/**
* comma_dias_check_string( $data )
*
* Hook for 'pre_term_{field}' to filter the correct/wrong diacritics
* @param String $data, user posted content
* @return String
*/
function comma_dias_check_string( $data ) {
$diacritics = comma_dias_get();
foreach( $diacritics as $wrong => $right )
$data = str_replace( $wrong, $right, $data );
return $data;
}
/**
* comma_dias_check_array( $data )
*
* Hook for 'wp_insert_post_data' to filter the correct/wrong diacritics
* @param Array $data, user posted content
* @return Array
*/
function comma_dias_check_array( $data ) {
if( !is_array( $data ) )
return $data;
$diacritics = comma_dias_get();
foreach( $diacritics as $wrong => $right ) {
$data['post_title'] = str_replace( $wrong, $right, $data['post_title'] );
$data['post_excerpt'] = str_replace( $wrong, $right, $data['post_excerpt'] );
$data['post_content'] = str_replace( $wrong, $right, $data['post_content'] );
}
return $data;
}
/**
* comma_dias_enqueues()
*
* Sets up the enqueues that add the compatibility layer for Windows platform
*/
function comma_dias_enqueues() {
// Skip if in wp-admin
if( defined( 'WP_ADMIN' ) && WP_ADMIN == true )
return;
wp_register_script( 'commadias', plugins_url( '/js/commadias.plugin.js', __FILE__ ), array( 'jquery' ), COMMA_DIAS_VERSION );
wp_enqueue_script( 'comma_dias_check', plugins_url( '/js/comma_dias_check.js', __FILE__ ), array( 'commadias' ), COMMA_DIAS_VERSION, true );
}
/* Register the hooks */
add_filter( 'esc_html', 'comma_dias_check_string' ); // blogname and blogdescription
add_filter( 'sanitize_title', 'comma_dias_check_string' ); // categories use this
add_filter( 'pre_term_name', 'comma_dias_check_string' ); // term name use this
add_filter( 'pre_term_description', 'comma_dias_check_string' ); // term description uses this
add_filter( 'wp_insert_post_data', 'comma_dias_check_array' ); // post and pages content uses this
add_action( 'init', 'comma_dias_enqueues' );
?>