Version Description
(22.02.2020) = * Fixed non-conversion of slugs with WPML * Restricted conversion of post to public and nav_menu_item * Introduced ctl_post_types filter
Download this release
Release Info
Developer | mihdan |
Plugin | Cyr-To-Lat |
Version | 4.3.4 |
Comparing to | |
See all releases |
Code changes from version 4.3.3 to 4.3.4
- classes/class-conversion-tables.php +1 -0
- classes/class-converter.php +6 -1
- classes/class-main.php +44 -49
- cyr-to-lat.php +3 -3
- readme.txt +7 -2
classes/class-conversion-tables.php
CHANGED
@@ -243,6 +243,7 @@ class Conversion_Tables {
|
|
243 |
];
|
244 |
break;
|
245 |
// Macedonian.
|
|
|
246 |
case 'mk_MK':
|
247 |
$table = [
|
248 |
'А' => 'A',
|
243 |
];
|
244 |
break;
|
245 |
// Macedonian.
|
246 |
+
// @link https://ru.wikipedia.org/wiki/ISO_9#%D0%A2%D0%B0%D0%B1%D0%BB._2._%D0%A2%D1%80%D0%B0%D0%BD%D1%81%D0%BB%D0%B8%D1%82%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F_%D0%BF%D0%BE_%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B5_%D0%91.
|
247 |
case 'mk_MK':
|
248 |
$table = [
|
249 |
'А' => 'A',
|
classes/class-converter.php
CHANGED
@@ -179,8 +179,13 @@ class Converter {
|
|
179 |
|
180 |
$regexp = Main::PROHIBITED_CHARS_REGEX . '+';
|
181 |
|
|
|
|
|
|
|
|
|
|
|
182 |
$defaults = [
|
183 |
-
'post_type' =>
|
184 |
'post_status' => [ 'publish', 'future', 'private' ],
|
185 |
];
|
186 |
|
179 |
|
180 |
$regexp = Main::PROHIBITED_CHARS_REGEX . '+';
|
181 |
|
182 |
+
$post_types = get_post_types( [ 'public' => true ] );
|
183 |
+
$post_types += [
|
184 |
+
'nav_menu_item' => 'nav_menu_item',
|
185 |
+
];
|
186 |
+
|
187 |
$defaults = [
|
188 |
+
'post_type' => apply_filters( 'ctl_post_types', $post_types ),
|
189 |
'post_status' => [ 'publish', 'future', 'private' ],
|
190 |
];
|
191 |
|
classes/class-main.php
CHANGED
@@ -110,53 +110,61 @@ class Main {
|
|
110 |
* Init class hooks.
|
111 |
*/
|
112 |
public function init_hooks() {
|
113 |
-
add_filter( '
|
114 |
-
add_filter( 'wp_unique_term_slug', [ $this, 'wp_unique_term_slug_filter' ], 10, 3 );
|
115 |
-
add_filter( 'pre_term_slug', [ $this, 'pre_term_slug_filter' ], 10, 2 );
|
116 |
-
|
117 |
add_filter( 'sanitize_file_name', [ $this, 'ctl_sanitize_filename' ], 10, 2 );
|
118 |
add_filter( 'wp_insert_post_data', [ $this, 'ctl_sanitize_post_name' ], 10, 2 );
|
119 |
}
|
120 |
|
121 |
/**
|
122 |
-
*
|
123 |
*
|
124 |
-
* @param string $
|
125 |
-
* @param
|
126 |
-
* @param string $
|
127 |
-
* @param string $post_type Post type.
|
128 |
-
* @param int $post_parent Post parent ID.
|
129 |
-
* @param string $original_slug The original post slug.
|
130 |
*
|
131 |
* @return string
|
132 |
*/
|
133 |
-
public function
|
134 |
-
|
135 |
-
}
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
* @param string $slug Unique term slug.
|
141 |
-
* @param object $term Term object.
|
142 |
-
* @param string $original_slug Slug originally passed to the function for testing.
|
143 |
-
*
|
144 |
-
* @return string
|
145 |
-
*/
|
146 |
-
public function wp_unique_term_slug_filter( $slug, $term, $original_slug ) {
|
147 |
-
return $this->transliterate_encoded( $slug );
|
148 |
-
}
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
}
|
161 |
|
162 |
/**
|
@@ -229,17 +237,6 @@ class Main {
|
|
229 |
return $string;
|
230 |
}
|
231 |
|
232 |
-
/**
|
233 |
-
* Transliterate encoded url.
|
234 |
-
*
|
235 |
-
* @param string $url Url.
|
236 |
-
*
|
237 |
-
* @return string
|
238 |
-
*/
|
239 |
-
private function transliterate_encoded( $url ) {
|
240 |
-
return rawurlencode( $this->transliterate( urldecode( $url ) ) );
|
241 |
-
}
|
242 |
-
|
243 |
/**
|
244 |
* Get transliteration table.
|
245 |
*
|
@@ -283,8 +280,6 @@ class Main {
|
|
283 |
// @codeCoverageIgnoreStart
|
284 |
/**
|
285 |
* Do not inspect include path.
|
286 |
-
*
|
287 |
-
* @noinspection PhpIncludeInspection
|
288 |
*/
|
289 |
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
290 |
// @codeCoverageIgnoreEnd
|
110 |
* Init class hooks.
|
111 |
*/
|
112 |
public function init_hooks() {
|
113 |
+
add_filter( 'sanitize_title', [ $this, 'ctl_sanitize_title' ], 9, 3 );
|
|
|
|
|
|
|
114 |
add_filter( 'sanitize_file_name', [ $this, 'ctl_sanitize_filename' ], 10, 2 );
|
115 |
add_filter( 'wp_insert_post_data', [ $this, 'ctl_sanitize_post_name' ], 10, 2 );
|
116 |
}
|
117 |
|
118 |
/**
|
119 |
+
* Sanitize title.
|
120 |
*
|
121 |
+
* @param string $title Sanitized title.
|
122 |
+
* @param string $raw_title The title prior to sanitization.
|
123 |
+
* @param string $context The context for which the title is being sanitized.
|
|
|
|
|
|
|
124 |
*
|
125 |
* @return string
|
126 |
*/
|
127 |
+
public function ctl_sanitize_title( $title, $raw_title = '', $context = '' ) {
|
128 |
+
global $wpdb;
|
|
|
129 |
|
130 |
+
if ( ! $title ) {
|
131 |
+
return $title;
|
132 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
+
// Fixed bug with `_wp_old_slug` redirect.
|
135 |
+
if ( 'query' === $context ) {
|
136 |
+
return $title;
|
137 |
+
}
|
138 |
+
|
139 |
+
$title = urldecode( $title );
|
140 |
+
$pre = apply_filters( 'ctl_pre_sanitize_title', false, $title );
|
141 |
+
|
142 |
+
if ( false !== $pre ) {
|
143 |
+
return $pre;
|
144 |
+
}
|
145 |
+
|
146 |
+
$is_term = false;
|
147 |
+
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
|
148 |
+
$backtrace = debug_backtrace( ~DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS );
|
149 |
+
// phpcs:enable
|
150 |
+
foreach ( $backtrace as $backtrace_entry ) {
|
151 |
+
if ( 'wp_insert_term' === $backtrace_entry['function'] ) {
|
152 |
+
$is_term = true;
|
153 |
+
break;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
// phpcs:disable WordPress.DB.DirectDatabaseQuery
|
158 |
+
$term = $is_term ? $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE name = %s", $title ) ) : '';
|
159 |
+
// phpcs:enable
|
160 |
+
|
161 |
+
if ( ! empty( $term ) ) {
|
162 |
+
$title = $term;
|
163 |
+
} else {
|
164 |
+
$title = $this->transliterate( $title );
|
165 |
+
}
|
166 |
+
|
167 |
+
return $title;
|
168 |
}
|
169 |
|
170 |
/**
|
237 |
return $string;
|
238 |
}
|
239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
/**
|
241 |
* Get transliteration table.
|
242 |
*
|
280 |
// @codeCoverageIgnoreStart
|
281 |
/**
|
282 |
* Do not inspect include path.
|
|
|
|
|
283 |
*/
|
284 |
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
285 |
// @codeCoverageIgnoreEnd
|
cyr-to-lat.php
CHANGED
@@ -9,8 +9,8 @@
|
|
9 |
* Author URI: https://profiles.wordpress.org/sergeybiryukov/
|
10 |
* Requires at least: 5.1
|
11 |
* Tested up to: 5.3
|
12 |
-
* Version: 4.3.
|
13 |
-
* Stable tag: 4.3.
|
14 |
*
|
15 |
* Text Domain: cyr2lat
|
16 |
* Domain Path: /languages/
|
@@ -30,7 +30,7 @@ if ( ! defined( 'CYR_TO_LAT_VERSION' ) ) {
|
|
30 |
/**
|
31 |
* Plugin version.
|
32 |
*/
|
33 |
-
define( 'CYR_TO_LAT_VERSION', '4.3.
|
34 |
}
|
35 |
|
36 |
if ( ! defined( 'CYR_TO_LAT_PATH' ) ) {
|
9 |
* Author URI: https://profiles.wordpress.org/sergeybiryukov/
|
10 |
* Requires at least: 5.1
|
11 |
* Tested up to: 5.3
|
12 |
+
* Version: 4.3.4
|
13 |
+
* Stable tag: 4.3.4
|
14 |
*
|
15 |
* Text Domain: cyr2lat
|
16 |
* Domain Path: /languages/
|
30 |
/**
|
31 |
* Plugin version.
|
32 |
*/
|
33 |
+
define( 'CYR_TO_LAT_VERSION', '4.3.4' );
|
34 |
}
|
35 |
|
36 |
if ( ! defined( 'CYR_TO_LAT_PATH' ) ) {
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: SergeyBiryukov, mihdan, karevn, webvitaly, kaggdesign
|
|
3 |
Tags: cyrillic, belorussian, ukrainian, bulgarian, macedonian, georgian, kazakh, latin, l10n, russian, cyr-to-lat, cyr2lat, rustolat, slugs, translations, transliteration
|
4 |
Requires at least: 5.1
|
5 |
Tested up to: 5.3
|
6 |
-
Stable tag: 4.3.
|
7 |
Requires PHP: 5.6.20
|
8 |
|
9 |
Converts Cyrillic characters in post, page and term slugs to Latin characters.
|
@@ -91,7 +91,12 @@ Yes you can!
|
|
91 |
|
92 |
== Changelog ==
|
93 |
|
94 |
-
= 4.3.
|
|
|
|
|
|
|
|
|
|
|
95 |
* Reworked main plugin filter
|
96 |
* Improved performance by minimizing number of calls
|
97 |
* Updated Georgian table
|
3 |
Tags: cyrillic, belorussian, ukrainian, bulgarian, macedonian, georgian, kazakh, latin, l10n, russian, cyr-to-lat, cyr2lat, rustolat, slugs, translations, transliteration
|
4 |
Requires at least: 5.1
|
5 |
Tested up to: 5.3
|
6 |
+
Stable tag: 4.3.4
|
7 |
Requires PHP: 5.6.20
|
8 |
|
9 |
Converts Cyrillic characters in post, page and term slugs to Latin characters.
|
91 |
|
92 |
== Changelog ==
|
93 |
|
94 |
+
= 4.3.4 (22.02.2020) =
|
95 |
+
* Fixed non-conversion of slugs with WPML
|
96 |
+
* Restricted conversion of post to public and nav_menu_item
|
97 |
+
* Introduced ctl_post_types filter
|
98 |
+
|
99 |
+
= 4.3.3 (20.02.2020) =
|
100 |
* Reworked main plugin filter
|
101 |
* Improved performance by minimizing number of calls
|
102 |
* Updated Georgian table
|