Cyr-To-Lat - Version 3.6.4

Version Description

(06.02.2019) = * Fixed bug with _wp_old_slug redirect. * Fixed bug with urldecode in posts.

Download this release

Release Info

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

Code changes from version 3.6.3 to 3.6.4

cyr-to-lat.php CHANGED
@@ -9,8 +9,8 @@
9
  * Author URI: https://profiles.wordpress.org/sergeybiryukov/
10
  * Requires at least: 2.3
11
  * Tested up to: 5.1
12
- * Version: 3.6.3
13
- * Stable tag: 3.6.3
14
  *
15
  * Text Domain: cyr-to-lat
16
  * Domain Path: /languages/
@@ -41,7 +41,7 @@ define( 'CYR_TO_LAT_FILE', __FILE__ );
41
  /**
42
  * Plugin version.
43
  */
44
- define( 'CYR_TO_LAT_VERSION', '3.6.3' );
45
 
46
  /**
47
  * Init plugin class on plugin load.
9
  * Author URI: https://profiles.wordpress.org/sergeybiryukov/
10
  * Requires at least: 2.3
11
  * Tested up to: 5.1
12
+ * Version: 3.6.4
13
+ * Stable tag: 3.6.4
14
  *
15
  * Text Domain: cyr-to-lat
16
  * Domain Path: /languages/
41
  /**
42
  * Plugin version.
43
  */
44
+ define( 'CYR_TO_LAT_VERSION', '3.6.4' );
45
 
46
  /**
47
  * Init plugin class on plugin load.
includes/class-cyr-to-lat-converter.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Old slugs converter.
4
+ *
5
+ * @package cyr-to-lat
6
+ */
7
+
8
+ /**
9
+ * Class Cyr_To_Lat_Converter
10
+ *
11
+ * @class Cyr_To_Lat_Converter
12
+ */
13
+ class Cyr_To_Lat_Converter {
14
+
15
+ /**
16
+ * Plugin main class.
17
+ *
18
+ * @var Cyr_To_Lat_Main
19
+ */
20
+ private $main;
21
+
22
+ /**
23
+ * Plugin settings.
24
+ *
25
+ * @var Cyr_To_Lat_Settings
26
+ */
27
+ private $settings;
28
+
29
+ /**
30
+ * Cyr_To_Lat_Converter constructor.
31
+ *
32
+ * @param Cyr_To_Lat_Main $main Plugin main class.
33
+ * @param Cyr_To_Lat_Settings $settings Plugin settings.
34
+ */
35
+ public function __construct( Cyr_To_Lat_Main $main, Cyr_To_Lat_Settings $settings ) {
36
+ $this->main = $main;
37
+ $this->settings = $settings;
38
+ $this->init_hooks();
39
+ }
40
+
41
+ /**
42
+ * Init class hooks.
43
+ */
44
+ public function init_hooks() {
45
+ if ( 'yes' === $this->settings->get_option( 'convert_existing_slugs' ) ) {
46
+ $this->settings->set_option( 'convert_existing_slugs', 'no' );
47
+ add_action( 'shutdown', array( $this, 'convert_existing_slugs' ) );
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Convert Existing Slugs
53
+ */
54
+ public function convert_existing_slugs() {
55
+ global $wpdb;
56
+
57
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery
58
+ $posts = $wpdb->get_results( "SELECT ID, post_name FROM $wpdb->posts WHERE post_name REGEXP('[^A-Za-z0-9\-]+') AND post_status IN ('publish', 'future', 'private')" );
59
+ // phpcs:enable
60
+
61
+ foreach ( (array) $posts as $post ) {
62
+ $sanitized_name = $this->main->ctl_sanitize_title( urldecode( $post->post_name ) );
63
+
64
+ if ( $post->post_name !== $sanitized_name ) {
65
+ add_post_meta( $post->ID, '_wp_old_slug', $post->post_name );
66
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery
67
+ $wpdb->update( $wpdb->posts, array( 'post_name' => $sanitized_name ), array( 'ID' => $post->ID ) );
68
+ // phpcs:enable
69
+ }
70
+ }
71
+
72
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery
73
+ $terms = $wpdb->get_results( "SELECT term_id, slug FROM $wpdb->terms WHERE slug REGEXP('[^A-Za-z0-9\-]+') " );
74
+ // phpcs:enable
75
+
76
+ foreach ( (array) $terms as $term ) {
77
+ $sanitized_slug = $this->main->ctl_sanitize_title( urldecode( $term->slug ) );
78
+
79
+ if ( $term->slug !== $sanitized_slug ) {
80
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery
81
+ $wpdb->update( $wpdb->terms, array( 'slug' => $sanitized_slug ), array( 'term_id' => $term->term_id ) );
82
+ // phpcs:enable
83
+ }
84
+ }
85
+ }
86
+ }
includes/class-cyr-to-lat-main.php CHANGED
@@ -17,6 +17,13 @@ class Cyr_To_Lat_Main {
17
  */
18
  private $settings;
19
 
 
 
 
 
 
 
 
20
  /**
21
  * Cyr_To_Lat constructor.
22
  */
@@ -30,6 +37,21 @@ class Cyr_To_Lat_Main {
30
  */
31
  public function init() {
32
  $this->settings = new Cyr_To_Lat_Settings();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
34
 
35
  /**
@@ -39,11 +61,6 @@ class Cyr_To_Lat_Main {
39
  add_filter( 'sanitize_title', array( $this, 'ctl_sanitize_title' ), 9, 3 );
40
  add_filter( 'sanitize_file_name', array( $this, 'ctl_sanitize_title' ), 10, 2 );
41
  add_filter( 'wp_insert_post_data', array( $this, 'ctl_sanitize_post_name' ), 10, 2 );
42
-
43
- if ( 'yes' === $this->settings->get_option( 'convert_existing_slugs' ) ) {
44
- $this->settings->set_option( 'convert_existing_slugs', 'no' );
45
- add_action( 'shutdown', array( $this, 'convert_existing_slugs' ) );
46
- }
47
  }
48
 
49
  /**
@@ -58,7 +75,13 @@ class Cyr_To_Lat_Main {
58
  public function ctl_sanitize_title( $title, $raw_title = '', $context = '' ) {
59
  global $wpdb;
60
 
61
- $pre = apply_filters( 'ctl_pre_sanitize_title', false, $title );
 
 
 
 
 
 
62
 
63
  if ( false !== $pre ) {
64
  return $pre;
@@ -93,7 +116,7 @@ class Cyr_To_Lat_Main {
93
  $title = iconv( 'UTF-8', 'UTF-8//TRANSLIT//IGNORE', $title );
94
  }
95
 
96
- $title = preg_replace( "/[^A-Za-z0-9'_\-\.]/", '-', $title );
97
  $title = preg_replace( '/\-+/', '-', $title );
98
  $title = trim( $title, '-' );
99
  }
@@ -101,42 +124,6 @@ class Cyr_To_Lat_Main {
101
  return $title;
102
  }
103
 
104
- /**
105
- * Convert Existing Slugs
106
- */
107
- public function convert_existing_slugs() {
108
- global $wpdb;
109
-
110
- // phpcs:disable WordPress.DB.DirectDatabaseQuery
111
- $posts = $wpdb->get_results( "SELECT ID, post_name FROM $wpdb->posts WHERE post_name REGEXP('[^A-Za-z0-9\-]+') AND post_status IN ('publish', 'future', 'private')" );
112
- // phpcs:enable
113
-
114
- foreach ( (array) $posts as $post ) {
115
- $sanitized_name = $this->ctl_sanitize_title( urldecode( $post->post_name ) );
116
-
117
- if ( $post->post_name !== $sanitized_name ) {
118
- add_post_meta( $post->ID, '_wp_old_slug', $post->post_name );
119
- // phpcs:disable WordPress.DB.DirectDatabaseQuery
120
- $wpdb->update( $wpdb->posts, array( 'post_name' => $sanitized_name ), array( 'ID' => $post->ID ) );
121
- // phpcs:enable
122
- }
123
- }
124
-
125
- // phpcs:disable WordPress.DB.DirectDatabaseQuery
126
- $terms = $wpdb->get_results( "SELECT term_id, slug FROM $wpdb->terms WHERE slug REGEXP('[^A-Za-z0-9\-]+') " );
127
- // phpcs:enable
128
-
129
- foreach ( (array) $terms as $term ) {
130
- $sanitized_slug = $this->ctl_sanitize_title( urldecode( $term->slug ) );
131
-
132
- if ( $term->slug !== $sanitized_slug ) {
133
- // phpcs:disable WordPress.DB.DirectDatabaseQuery
134
- $wpdb->update( $wpdb->terms, array( 'slug' => $sanitized_slug ), array( 'term_id' => $term->term_id ) );
135
- // phpcs:enable
136
- }
137
- }
138
- }
139
-
140
  /**
141
  * Check if Classic Editor plugin is active.
142
  *
17
  */
18
  private $settings;
19
 
20
+ /**
21
+ * WP-CLI
22
+ *
23
+ * @var Cyr_To_Lat_WP_CLI
24
+ */
25
+ private $cli;
26
+
27
  /**
28
  * Cyr_To_Lat constructor.
29
  */
37
  */
38
  public function init() {
39
  $this->settings = new Cyr_To_Lat_Settings();
40
+
41
+ if ( defined( 'WP_CLI' ) && WP_CLI ) {
42
+ $converter = new Cyr_To_Lat_Converter( $this, $this->settings );
43
+ $this->cli = new Cyr_To_Lat_WP_CLI( $converter );
44
+ try {
45
+ /**
46
+ * Method WP_CLI::add_command() accepts class as callable.
47
+ *
48
+ * @noinspection PhpParamsInspection
49
+ */
50
+ WP_CLI::add_command( 'cyr2lat', $this->cli );
51
+ } catch ( Exception $e ) {
52
+ return;
53
+ }
54
+ }
55
  }
56
 
57
  /**
61
  add_filter( 'sanitize_title', array( $this, 'ctl_sanitize_title' ), 9, 3 );
62
  add_filter( 'sanitize_file_name', array( $this, 'ctl_sanitize_title' ), 10, 2 );
63
  add_filter( 'wp_insert_post_data', array( $this, 'ctl_sanitize_post_name' ), 10, 2 );
 
 
 
 
 
64
  }
65
 
66
  /**
75
  public function ctl_sanitize_title( $title, $raw_title = '', $context = '' ) {
76
  global $wpdb;
77
 
78
+ // Fixed bug with `_wp_old_slug` redirect.
79
+ if ( 'query' === $context ) {
80
+ return $title;
81
+ }
82
+
83
+ $title = urldecode( $title );
84
+ $pre = apply_filters( 'ctl_pre_sanitize_title', false, $title );
85
 
86
  if ( false !== $pre ) {
87
  return $pre;
116
  $title = iconv( 'UTF-8', 'UTF-8//TRANSLIT//IGNORE', $title );
117
  }
118
 
119
+ $title = preg_replace( "/[^A-Za-z0-9'_\-\.%]/", '-', $title );
120
  $title = preg_replace( '/\-+/', '-', $title );
121
  $title = trim( $title, '-' );
122
  }
124
  return $title;
125
  }
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  /**
128
  * Check if Classic Editor plugin is active.
129
  *
includes/class-cyr-to-lat-wp-cli.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WP-CLI support.
4
+ *
5
+ * @package cyr-to-lat
6
+ * @link https://github.com/mihdan/wp-rocket-cli/blob/master/command.php
7
+ */
8
+
9
+ /**
10
+ * Class Cyr_To_Lat_WP_CLI
11
+ *
12
+ * @class Cyr_To_Lat_WP_CLI
13
+ */
14
+ class Cyr_To_Lat_WP_CLI extends WP_CLI_Command {
15
+
16
+ /**
17
+ * Converter class.
18
+ *
19
+ * @var Cyr_To_Lat_Converter
20
+ */
21
+ private $converter;
22
+
23
+ /**
24
+ * Cyr_To_Lat_WP_CLI constructor.
25
+ *
26
+ * @param Cyr_To_Lat_Converter $converter Converter.
27
+ */
28
+ public function __construct( Cyr_To_Lat_Converter $converter ) {
29
+ parent::__construct();
30
+ $this->converter = $converter;
31
+ }
32
+
33
+ /**
34
+ * Regenerate old slugs.
35
+ *
36
+ * ## EXAMPLES
37
+ *
38
+ * $ wp cyr2lat regenerate
39
+ * Success: Regenerate Completed.
40
+ *
41
+ * @subcommand regenerate
42
+ *
43
+ * @param array $args Arguments.
44
+ * @param array $assoc_args Arguments in associative array.
45
+ */
46
+ public function regenerate( $args = array(), $assoc_args = array() ) {
47
+
48
+ /**
49
+ * Notify instance.
50
+ *
51
+ * @var \cli\progress\Bar $notify
52
+ */
53
+ $notify = \WP_CLI\Utils\make_progress_bar( 'Regenerate old slugs', 1 );
54
+
55
+ //for ( $i = 0; $i < 5; $i ++ ) {
56
+ /// sleep( wp_rand( 1, 2 ) );
57
+ // $notify->tick();
58
+ //}
59
+ //$notify->finish();
60
+
61
+ $this->converter->convert_existing_slugs();
62
+ $notify->tick();
63
+ $notify->finish();
64
+
65
+ WP_CLI::success( 'Regenerate Completed.' );
66
+ }
67
+ }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: SergeyBiryukov, mihdan, karevn, webvitaly, kaggdesign
3
  Tags: cyrillic, georgian, latin, l10n, russian, rustolat, slugs, translations, transliteration
4
  Requires at least: 2.3
5
  Tested up to: 5.1
6
- Stable tag: 3.6.3
7
  Requires PHP: 5.2
8
 
9
  Converts Cyrillic characters in post, page and term slugs to Latin characters.
@@ -46,6 +46,10 @@ Yes you can! Join in on our [GitHub repository](https://github.com/mihdan/cyr2la
46
 
47
  == Changelog ==
48
 
 
 
 
 
49
  = 3.6.3 (04.02.2019) =
50
  * Fixed bug with network activation on multisite
51
 
3
  Tags: cyrillic, georgian, latin, l10n, russian, rustolat, slugs, translations, transliteration
4
  Requires at least: 2.3
5
  Tested up to: 5.1
6
+ Stable tag: 3.6.4
7
  Requires PHP: 5.2
8
 
9
  Converts Cyrillic characters in post, page and term slugs to Latin characters.
46
 
47
  == Changelog ==
48
 
49
+ = 3.6.4 (06.02.2019) =
50
+ * Fixed bug with `_wp_old_slug` redirect.
51
+ * Fixed bug with `urldecode` in posts.
52
+
53
  = 3.6.3 (04.02.2019) =
54
  * Fixed bug with network activation on multisite
55
 
vendor/autoload_52.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once dirname(__FILE__) . '/composer'.'/autoload_real_52.php';
6
 
7
- return ComposerAutoloaderInitfb5d3f1dd75e3c85696a0ac7fd97b16f::getLoader();
4
 
5
  require_once dirname(__FILE__) . '/composer'.'/autoload_real_52.php';
6
 
7
+ return ComposerAutoloaderInit266b0aa0ebaaec076b4dabe0a066b31e::getLoader();
vendor/composer/autoload_classmap.php CHANGED
@@ -7,6 +7,8 @@ $baseDir = dirname($vendorDir);
7
 
8
  return array(
9
  'Cyr_To_Lat_Conversion_Tables' => $baseDir . '/includes/class-cyr-to-lat-conversion-tables.php',
 
10
  'Cyr_To_Lat_Main' => $baseDir . '/includes/class-cyr-to-lat-main.php',
11
  'Cyr_To_Lat_Settings' => $baseDir . '/includes/class-cyr-to-lat-settings.php',
 
12
  );
7
 
8
  return array(
9
  'Cyr_To_Lat_Conversion_Tables' => $baseDir . '/includes/class-cyr-to-lat-conversion-tables.php',
10
+ 'Cyr_To_Lat_Converter' => $baseDir . '/includes/class-cyr-to-lat-converter.php',
11
  'Cyr_To_Lat_Main' => $baseDir . '/includes/class-cyr-to-lat-main.php',
12
  'Cyr_To_Lat_Settings' => $baseDir . '/includes/class-cyr-to-lat-settings.php',
13
+ 'Cyr_To_Lat_WP_CLI' => $baseDir . '/includes/class-cyr-to-lat-wp-cli.php',
14
  );
vendor/composer/autoload_real_52.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real_52.php generated by xrstf/composer-php52
4
 
5
- class ComposerAutoloaderInitfb5d3f1dd75e3c85696a0ac7fd97b16f {
6
  private static $loader;
7
 
8
  public static function loadClassLoader($class) {
@@ -19,9 +19,9 @@ class ComposerAutoloaderInitfb5d3f1dd75e3c85696a0ac7fd97b16f {
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInitfb5d3f1dd75e3c85696a0ac7fd97b16f', 'loadClassLoader'), true /*, true */);
23
  self::$loader = $loader = new xrstf_Composer52_ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInitfb5d3f1dd75e3c85696a0ac7fd97b16f', 'loadClassLoader'));
25
 
26
  $vendorDir = dirname(dirname(__FILE__));
27
  $baseDir = dirname($vendorDir);
2
 
3
  // autoload_real_52.php generated by xrstf/composer-php52
4
 
5
+ class ComposerAutoloaderInit266b0aa0ebaaec076b4dabe0a066b31e {
6
  private static $loader;
7
 
8
  public static function loadClassLoader($class) {
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInit266b0aa0ebaaec076b4dabe0a066b31e', 'loadClassLoader'), true /*, true */);
23
  self::$loader = $loader = new xrstf_Composer52_ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInit266b0aa0ebaaec076b4dabe0a066b31e', 'loadClassLoader'));
25
 
26
  $vendorDir = dirname(dirname(__FILE__));
27
  $baseDir = dirname($vendorDir);
vendor/composer/autoload_static.php CHANGED
@@ -32,8 +32,10 @@ class ComposerStaticInitb7c5f930ec4fa1c83689fac301fc90e8
32
 
33
  public static $classMap = array (
34
  'Cyr_To_Lat_Conversion_Tables' => __DIR__ . '/../..' . '/includes/class-cyr-to-lat-conversion-tables.php',
 
35
  'Cyr_To_Lat_Main' => __DIR__ . '/../..' . '/includes/class-cyr-to-lat-main.php',
36
  'Cyr_To_Lat_Settings' => __DIR__ . '/../..' . '/includes/class-cyr-to-lat-settings.php',
 
37
  );
38
 
39
  public static function getInitializer(ClassLoader $loader)
32
 
33
  public static $classMap = array (
34
  'Cyr_To_Lat_Conversion_Tables' => __DIR__ . '/../..' . '/includes/class-cyr-to-lat-conversion-tables.php',
35
+ 'Cyr_To_Lat_Converter' => __DIR__ . '/../..' . '/includes/class-cyr-to-lat-converter.php',
36
  'Cyr_To_Lat_Main' => __DIR__ . '/../..' . '/includes/class-cyr-to-lat-main.php',
37
  'Cyr_To_Lat_Settings' => __DIR__ . '/../..' . '/includes/class-cyr-to-lat-settings.php',
38
+ 'Cyr_To_Lat_WP_CLI' => __DIR__ . '/../..' . '/includes/class-cyr-to-lat-wp-cli.php',
39
  );
40
 
41
  public static function getInitializer(ClassLoader $loader)