Cyr-To-Lat - Version 5.0.2

Version Description

(27.03.2021) = * Fix bug creating tag with the same slug as category

Download this release

Release Info

Developer mihdan
Plugin Icon 128x128 Cyr-To-Lat
Version 5.0.2
Comparing to
See all releases

Code changes from version 5.0.1 to 5.0.2

cyr-to-lat.php CHANGED
@@ -9,8 +9,8 @@
9
  *
10
  * Plugin Name: Cyr-To-Lat
11
  * Plugin URI: https://wordpress.org/plugins/cyr2lat/
12
- * Description: Converts Cyrillic characters in post and term slugs to Latin characters. Useful for creating human-readable URLs. Based on the original plugin by Anton Skorobogatov.
13
- * Version: 5.0.1
14
  * Requires at least: 5.1
15
  * Requires PHP: 5.6.20
16
  * Author: Sergey Biryukov, Mikhail Kobzarev, Igor Gergel
@@ -36,7 +36,7 @@ if ( defined( 'CYR_TO_LAT_VERSION' ) ) {
36
  /**
37
  * Plugin version.
38
  */
39
- define( 'CYR_TO_LAT_VERSION', '5.0.1' );
40
 
41
  /**
42
  * Path to the plugin dir.
9
  *
10
  * Plugin Name: Cyr-To-Lat
11
  * Plugin URI: https://wordpress.org/plugins/cyr2lat/
12
+ * Description: Convert Non-Latin characters in post and term slugs to Latin characters. Useful for creating human-readable URLs. Based on the original plugin by Anton Skorobogatov.
13
+ * Version: 5.0.2
14
  * Requires at least: 5.1
15
  * Requires PHP: 5.6.20
16
  * Author: Sergey Biryukov, Mikhail Kobzarev, Igor Gergel
36
  /**
37
  * Plugin version.
38
  */
39
+ define( 'CYR_TO_LAT_VERSION', '5.0.2' );
40
 
41
  /**
42
  * Path to the plugin dir.
readme.txt CHANGED
@@ -3,10 +3,10 @@ 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.7
6
- Stable tag: 5.0.1
7
  Requires PHP: 5.6.20
8
 
9
- Converts Cyrillic characters in post, page and term slugs to Latin characters.
10
 
11
  == Description ==
12
 
@@ -32,8 +32,9 @@ Based on the original Rus-To-Lat plugin by Anton Skorobogatov.
32
  3. Block editor with transliterated slug
33
 
34
  == Plugin Support ==
 
35
  * [Support Forum](https://wordpress.org/support/plugin/cyr2lat/)
36
- * [Telegram Channel](https://t.me/cyr2lat)
37
 
38
  == Installation ==
39
 
@@ -178,12 +179,15 @@ Where
178
  Yes you can!
179
 
180
  * Join in on our [GitHub repository](https://github.com/mihdan/cyr2lat)
181
- * Join in on our [Telegram Channel](https://t.me/cyr2lat)
182
 
183
  == Changelog ==
184
 
 
 
 
185
  = 5.0.1 (22.03.2021) =
186
- * Fixed fatal error during plugin load on some servers
187
 
188
  = 5.0.0 (18.03.2021) =
189
  * Introduce tabs on options page
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.7
6
+ Stable tag: 5.0.2
7
  Requires PHP: 5.6.20
8
 
9
+ Convert Non-Latin characters in post, page and term slugs to Latin characters.
10
 
11
  == Description ==
12
 
32
  3. Block editor with transliterated slug
33
 
34
  == Plugin Support ==
35
+
36
  * [Support Forum](https://wordpress.org/support/plugin/cyr2lat/)
37
+ * [Telegram Group](https://t.me/cyr2lat)
38
 
39
  == Installation ==
40
 
179
  Yes you can!
180
 
181
  * Join in on our [GitHub repository](https://github.com/mihdan/cyr2lat)
182
+ * Join in on our [Telegram Group](https://t.me/cyr2lat)
183
 
184
  == Changelog ==
185
 
186
+ = 5.0.2 (27.03.2021) =
187
+ * Fix bug creating tag with the same slug as category
188
+
189
  = 5.0.1 (22.03.2021) =
190
+ * Fix fatal error during plugin load on some servers
191
 
192
  = 5.0.0 (18.03.2021) =
193
  * Introduce tabs on options page
src/php/class-main.php CHANGED
@@ -7,6 +7,7 @@
7
 
8
  namespace Cyr_To_Lat;
9
 
 
10
  use wpdb;
11
  use Exception;
12
  use Cyr_To_Lat\Settings\Settings;
@@ -66,6 +67,20 @@ class Main {
66
  */
67
  protected $acf;
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  /**
70
  * Polylang locale.
71
  *
@@ -131,6 +146,7 @@ class Main {
131
  add_filter( 'sanitize_title', [ $this, 'sanitize_title' ], 9, 3 );
132
  add_filter( 'sanitize_file_name', [ $this, 'sanitize_filename' ], 10, 2 );
133
  add_filter( 'wp_insert_post_data', [ $this, 'sanitize_post_name' ], 10, 2 );
 
134
 
135
  if ( class_exists( 'Polylang' ) ) {
136
  add_filter( 'locale', [ $this, 'pll_locale_filter' ] );
@@ -177,9 +193,24 @@ class Main {
177
  }
178
  }
179
 
180
- // phpcs:disable WordPress.DB.DirectDatabaseQuery
181
- $term = $is_term ? $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE name = %s", $title ) ) : '';
182
- // phpcs:enable
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
  if ( ! empty( $term ) ) {
185
  $title = $term;
@@ -311,6 +342,7 @@ class Main {
311
 
312
  if ( function_exists( 'iconv' ) ) {
313
  $new_string = iconv( 'UTF-8', 'UTF-8//TRANSLIT//IGNORE', $string );
 
314
  return $new_string ?: $string;
315
  }
316
 
@@ -323,13 +355,13 @@ class Main {
323
  * @link https://kagg.eu/how-to-catch-gutenberg/
324
  *
325
  * @return bool
326
- * @noinspection PhpIncludeInspection
327
  */
328
  private function is_classic_editor_plugin_active() {
329
  // @codeCoverageIgnoreStart
330
  if ( ! function_exists( 'is_plugin_active' ) ) {
331
  include_once ABSPATH . 'wp-admin/includes/plugin.php';
332
  }
 
333
  // @codeCoverageIgnoreEnd
334
 
335
  return is_plugin_active( 'classic-editor/classic-editor.php' );
@@ -396,6 +428,32 @@ class Main {
396
  return $data;
397
  }
398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  /**
400
  * Locale filter for Polylang.
401
  *
@@ -518,6 +576,7 @@ class Main {
518
  $pll_get_term_language = $pll_get_language->locale;
519
  }
520
  }
 
521
  // phpcs:enable WordPress.Security.NonceVerification.Missing
522
 
523
  return $pll_get_term_language;
7
 
8
  namespace Cyr_To_Lat;
9
 
10
+ use WP_Error;
11
  use wpdb;
12
  use Exception;
13
  use Cyr_To_Lat\Settings\Settings;
67
  */
68
  protected $acf;
69
 
70
+ /**
71
+ * Term saved in pre_insert_term filter.
72
+ *
73
+ * @var string|WP_Error|null
74
+ */
75
+ private $term;
76
+
77
+ /**
78
+ * Taxonomy saved in pre_insert_term filter.
79
+ *
80
+ * @var string|null
81
+ */
82
+ private $taxonomy;
83
+
84
  /**
85
  * Polylang locale.
86
  *
146
  add_filter( 'sanitize_title', [ $this, 'sanitize_title' ], 9, 3 );
147
  add_filter( 'sanitize_file_name', [ $this, 'sanitize_filename' ], 10, 2 );
148
  add_filter( 'wp_insert_post_data', [ $this, 'sanitize_post_name' ], 10, 2 );
149
+ add_filter( 'pre_insert_term', [ $this, 'pre_term_filter' ], PHP_INT_MAX, 2 );
150
 
151
  if ( class_exists( 'Polylang' ) ) {
152
  add_filter( 'locale', [ $this, 'pll_locale_filter' ] );
193
  }
194
  }
195
 
196
+ $term = '';
197
+ if ( $is_term && null !== $this->term && null !== $this->taxonomy ) {
198
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery
199
+ $term = $wpdb->get_var(
200
+ $wpdb->prepare(
201
+ "SELECT slug FROM $wpdb->terms t LEFT JOIN $wpdb->term_taxonomy tt
202
+ ON t.term_id = tt.term_id
203
+ WHERE t.name = %s AND tt.taxonomy = %s",
204
+ $title,
205
+ $this->taxonomy
206
+ )
207
+ );
208
+ // phpcs:enable
209
+
210
+ // Make sure we search in the db only once being called from wp_insert_term().
211
+ $this->term = null;
212
+ $this->taxonomy = null;
213
+ }
214
 
215
  if ( ! empty( $term ) ) {
216
  $title = $term;
342
 
343
  if ( function_exists( 'iconv' ) ) {
344
  $new_string = iconv( 'UTF-8', 'UTF-8//TRANSLIT//IGNORE', $string );
345
+
346
  return $new_string ?: $string;
347
  }
348
 
355
  * @link https://kagg.eu/how-to-catch-gutenberg/
356
  *
357
  * @return bool
 
358
  */
359
  private function is_classic_editor_plugin_active() {
360
  // @codeCoverageIgnoreStart
361
  if ( ! function_exists( 'is_plugin_active' ) ) {
362
  include_once ABSPATH . 'wp-admin/includes/plugin.php';
363
  }
364
+
365
  // @codeCoverageIgnoreEnd
366
 
367
  return is_plugin_active( 'classic-editor/classic-editor.php' );
428
  return $data;
429
  }
430
 
431
+ /**
432
+ * Filters a term before it is sanitized and inserted into the database.
433
+ *
434
+ * @param string|int|WP_Error $term The term name to add, or a WP_Error object if there's an error.
435
+ * @param string $taxonomy Taxonomy slug.
436
+ *
437
+ * @return mixed
438
+ */
439
+ public function pre_term_filter( $term, $taxonomy ) {
440
+ $this->term = null;
441
+ $this->taxonomy = null;
442
+
443
+ if (
444
+ 0 === $term ||
445
+ '' === trim( $term ) ||
446
+ is_wp_error( $term )
447
+ ) {
448
+ return $term;
449
+ }
450
+
451
+ $this->term = $term;
452
+ $this->taxonomy = $taxonomy;
453
+
454
+ return $term;
455
+ }
456
+
457
  /**
458
  * Locale filter for Polylang.
459
  *
576
  $pll_get_term_language = $pll_get_language->locale;
577
  }
578
  }
579
+
580
  // phpcs:enable WordPress.Security.NonceVerification.Missing
581
 
582
  return $pll_get_term_language;
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInitce519c7cde52ecd209b7f65d782cf8f2::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit681e309def2815858e5a28423a87233c::getLoader();
vendor/composer/InstalledVersions.php CHANGED
@@ -25,12 +25,12 @@ class InstalledVersions
25
  private static $installed = array (
26
  'root' =>
27
  array (
28
- 'pretty_version' => '5.0.1',
29
- 'version' => '5.0.1.0',
30
  'aliases' =>
31
  array (
32
  ),
33
- 'reference' => '6538fd2c42bcc7646d1ed8aea4bb0d101cf145bd',
34
  'name' => 'mihdan/cyr2lat',
35
  ),
36
  'versions' =>
@@ -46,12 +46,12 @@ private static $installed = array (
46
  ),
47
  'mihdan/cyr2lat' =>
48
  array (
49
- 'pretty_version' => '5.0.1',
50
- 'version' => '5.0.1.0',
51
  'aliases' =>
52
  array (
53
  ),
54
- 'reference' => '6538fd2c42bcc7646d1ed8aea4bb0d101cf145bd',
55
  ),
56
  'roundcube/plugin-installer' =>
57
  array (
25
  private static $installed = array (
26
  'root' =>
27
  array (
28
+ 'pretty_version' => '5.0.2',
29
+ 'version' => '5.0.2.0',
30
  'aliases' =>
31
  array (
32
  ),
33
+ 'reference' => 'b13080f905519be869babc177891b40de5b81b00',
34
  'name' => 'mihdan/cyr2lat',
35
  ),
36
  'versions' =>
46
  ),
47
  'mihdan/cyr2lat' =>
48
  array (
49
+ 'pretty_version' => '5.0.2',
50
+ 'version' => '5.0.2.0',
51
  'aliases' =>
52
  array (
53
  ),
54
+ 'reference' => 'b13080f905519be869babc177891b40de5b81b00',
55
  ),
56
  'roundcube/plugin-installer' =>
57
  array (
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInitce519c7cde52ecd209b7f65d782cf8f2
6
  {
7
  private static $loader;
8
 
@@ -22,15 +22,15 @@ class ComposerAutoloaderInitce519c7cde52ecd209b7f65d782cf8f2
22
  return self::$loader;
23
  }
24
 
25
- spl_autoload_register(array('ComposerAutoloaderInitce519c7cde52ecd209b7f65d782cf8f2', 'loadClassLoader'), true, true);
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
27
- spl_autoload_unregister(array('ComposerAutoloaderInitce519c7cde52ecd209b7f65d782cf8f2', 'loadClassLoader'));
28
 
29
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
  if ($useStaticLoader) {
31
  require __DIR__ . '/autoload_static.php';
32
 
33
- call_user_func(\Composer\Autoload\ComposerStaticInitce519c7cde52ecd209b7f65d782cf8f2::getInitializer($loader));
34
  } else {
35
  $map = require __DIR__ . '/autoload_namespaces.php';
36
  foreach ($map as $namespace => $path) {
@@ -51,19 +51,19 @@ class ComposerAutoloaderInitce519c7cde52ecd209b7f65d782cf8f2
51
  $loader->register(true);
52
 
53
  if ($useStaticLoader) {
54
- $includeFiles = Composer\Autoload\ComposerStaticInitce519c7cde52ecd209b7f65d782cf8f2::$files;
55
  } else {
56
  $includeFiles = require __DIR__ . '/autoload_files.php';
57
  }
58
  foreach ($includeFiles as $fileIdentifier => $file) {
59
- composerRequirece519c7cde52ecd209b7f65d782cf8f2($fileIdentifier, $file);
60
  }
61
 
62
  return $loader;
63
  }
64
  }
65
 
66
- function composerRequirece519c7cde52ecd209b7f65d782cf8f2($fileIdentifier, $file)
67
  {
68
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
69
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInit681e309def2815858e5a28423a87233c
6
  {
7
  private static $loader;
8
 
22
  return self::$loader;
23
  }
24
 
25
+ spl_autoload_register(array('ComposerAutoloaderInit681e309def2815858e5a28423a87233c', 'loadClassLoader'), true, true);
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
27
+ spl_autoload_unregister(array('ComposerAutoloaderInit681e309def2815858e5a28423a87233c', 'loadClassLoader'));
28
 
29
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
  if ($useStaticLoader) {
31
  require __DIR__ . '/autoload_static.php';
32
 
33
+ call_user_func(\Composer\Autoload\ComposerStaticInit681e309def2815858e5a28423a87233c::getInitializer($loader));
34
  } else {
35
  $map = require __DIR__ . '/autoload_namespaces.php';
36
  foreach ($map as $namespace => $path) {
51
  $loader->register(true);
52
 
53
  if ($useStaticLoader) {
54
+ $includeFiles = Composer\Autoload\ComposerStaticInit681e309def2815858e5a28423a87233c::$files;
55
  } else {
56
  $includeFiles = require __DIR__ . '/autoload_files.php';
57
  }
58
  foreach ($includeFiles as $fileIdentifier => $file) {
59
+ composerRequire681e309def2815858e5a28423a87233c($fileIdentifier, $file);
60
  }
61
 
62
  return $loader;
63
  }
64
  }
65
 
66
+ function composerRequire681e309def2815858e5a28423a87233c($fileIdentifier, $file)
67
  {
68
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
69
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInitce519c7cde52ecd209b7f65d782cf8f2
8
  {
9
  public static $files = array (
10
  '344a0f93a05b8ca362c22e39586db500' => __DIR__ . '/../..' . '/lib/polyfill-mbstring/bootstrap.php',
@@ -50,9 +50,9 @@ class ComposerStaticInitce519c7cde52ecd209b7f65d782cf8f2
50
  public static function getInitializer(ClassLoader $loader)
51
  {
52
  return \Closure::bind(function () use ($loader) {
53
- $loader->prefixLengthsPsr4 = ComposerStaticInitce519c7cde52ecd209b7f65d782cf8f2::$prefixLengthsPsr4;
54
- $loader->prefixDirsPsr4 = ComposerStaticInitce519c7cde52ecd209b7f65d782cf8f2::$prefixDirsPsr4;
55
- $loader->classMap = ComposerStaticInitce519c7cde52ecd209b7f65d782cf8f2::$classMap;
56
 
57
  }, null, ClassLoader::class);
58
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInit681e309def2815858e5a28423a87233c
8
  {
9
  public static $files = array (
10
  '344a0f93a05b8ca362c22e39586db500' => __DIR__ . '/../..' . '/lib/polyfill-mbstring/bootstrap.php',
50
  public static function getInitializer(ClassLoader $loader)
51
  {
52
  return \Closure::bind(function () use ($loader) {
53
+ $loader->prefixLengthsPsr4 = ComposerStaticInit681e309def2815858e5a28423a87233c::$prefixLengthsPsr4;
54
+ $loader->prefixDirsPsr4 = ComposerStaticInit681e309def2815858e5a28423a87233c::$prefixDirsPsr4;
55
+ $loader->classMap = ComposerStaticInit681e309def2815858e5a28423a87233c::$classMap;
56
 
57
  }, null, ClassLoader::class);
58
  }
vendor/composer/installed.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php return array (
2
  'root' =>
3
  array (
4
- 'pretty_version' => '5.0.1',
5
- 'version' => '5.0.1.0',
6
  'aliases' =>
7
  array (
8
  ),
9
- 'reference' => '6538fd2c42bcc7646d1ed8aea4bb0d101cf145bd',
10
  'name' => 'mihdan/cyr2lat',
11
  ),
12
  'versions' =>
@@ -22,12 +22,12 @@
22
  ),
23
  'mihdan/cyr2lat' =>
24
  array (
25
- 'pretty_version' => '5.0.1',
26
- 'version' => '5.0.1.0',
27
  'aliases' =>
28
  array (
29
  ),
30
- 'reference' => '6538fd2c42bcc7646d1ed8aea4bb0d101cf145bd',
31
  ),
32
  'roundcube/plugin-installer' =>
33
  array (
1
  <?php return array (
2
  'root' =>
3
  array (
4
+ 'pretty_version' => '5.0.2',
5
+ 'version' => '5.0.2.0',
6
  'aliases' =>
7
  array (
8
  ),
9
+ 'reference' => 'b13080f905519be869babc177891b40de5b81b00',
10
  'name' => 'mihdan/cyr2lat',
11
  ),
12
  'versions' =>
22
  ),
23
  'mihdan/cyr2lat' =>
24
  array (
25
+ 'pretty_version' => '5.0.2',
26
+ 'version' => '5.0.2.0',
27
  'aliases' =>
28
  array (
29
  ),
30
+ 'reference' => 'b13080f905519be869babc177891b40de5b81b00',
31
  ),
32
  'roundcube/plugin-installer' =>
33
  array (