diff --git a/classes/background-processes/class-post-conversion-process.php b/classes/background-processes/class-post-conversion-process.php index 35ac1b3..e7b362e 100644 --- a/classes/background-processes/class-post-conversion-process.php +++ b/classes/background-processes/class-post-conversion-process.php @@ -65,7 +65,7 @@ protected function task( $post ) { if ( $transliterated_name !== $post_name ) { update_post_meta( $post->ID, '_wp_old_slug', $post_name ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery - $wpdb->update( $wpdb->posts, [ 'post_name' => urlencode( $transliterated_name ) ], [ 'ID' => $post->ID ] ); + $wpdb->update( $wpdb->posts, [ 'post_name' => rawurlencode( $transliterated_name ) ], [ 'ID' => $post->ID ] ); $this->log( __( 'Post slug converted:', 'cyr2lat' ) . ' ' . $post_name . ' => ' . $transliterated_name ); } diff --git a/classes/background-processes/class-term-conversion-process.php b/classes/background-processes/class-term-conversion-process.php index d29f397..a0a1304 100644 --- a/classes/background-processes/class-term-conversion-process.php +++ b/classes/background-processes/class-term-conversion-process.php @@ -64,7 +64,7 @@ protected function task( $term ) { if ( $transliterated_slug !== $slug ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery - $wpdb->update( $wpdb->terms, [ 'slug' => urlencode( $transliterated_slug ) ], [ 'term_id' => $term->term_id ] ); + $wpdb->update( $wpdb->terms, [ 'slug' => rawurlencode( $transliterated_slug ) ], [ 'term_id' => $term->term_id ] ); $this->log( __( 'Term slug converted:', 'cyr2lat' ) . ' ' . $slug . ' => ' . $transliterated_slug ); } diff --git a/classes/class-conversion-tables.php b/classes/class-conversion-tables.php index da699d3..b83065c 100644 --- a/classes/class-conversion-tables.php +++ b/classes/class-conversion-tables.php @@ -553,13 +553,13 @@ public static function get( $locale = '' ) { 'ת' => 'th', ]; for ( $code = 0x0590; $code <= 0x05CF; $code ++ ) { - $table[ mb_chr( $code ) ] = ''; + $table[ Mbstring::mb_chr( $code ) ] = ''; } for ( $code = 0x05F0; $code <= 0x05F5; $code ++ ) { - $table[ mb_chr( $code ) ] = ''; + $table[ Mbstring::mb_chr( $code ) ] = ''; } for ( $code = 0xFB1D; $code <= 0xFB4F; $code ++ ) { - $table[ mb_chr( $code ) ] = ''; + $table[ Mbstring::mb_chr( $code ) ] = ''; } break; // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment diff --git a/classes/class-main.php b/classes/class-main.php index 934845a..e7d181a 100644 --- a/classes/class-main.php +++ b/classes/class-main.php @@ -125,16 +125,18 @@ public function init_hooks() { * @param int $post_ID Post ID. * @param string $post_status The post status. * @param string $post_type Post type. - * @param int $post_parent Post parent ID + * @param int $post_parent Post parent ID. * @param string $original_slug The original post slug. * * @return string */ public function wp_unique_post_slug_filter( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) { - return urlencode( $this->transliterate( urldecode( $slug ) ) ); + return $this->transliterate_encoded( $slug ); } /** + * Filter wp_unique_term_slug. + * * @param string $slug Unique term slug. * @param object $term Term object. * @param string $original_slug Slug originally passed to the function for testing. @@ -142,17 +144,19 @@ public function wp_unique_post_slug_filter( $slug, $post_ID, $post_status, $post * @return string */ public function wp_unique_term_slug_filter( $slug, $term, $original_slug ) { - return urlencode( $this->transliterate( urldecode( $slug ) ) ); + return $this->transliterate_encoded( $slug ); } /** + * Filter pre_term_slug. + * * @param mixed $value Value of the term field. * @param string $taxonomy Taxonomy slug. * * @return string */ public function pre_term_slug_filter( $value, $taxonomy ) { - return urlencode( $this->transliterate( urldecode( $value ) ) ); + return $this->transliterate_encoded( $value ); } /** @@ -211,7 +215,7 @@ protected function split_chinese_string( $string, $table ) { return $string; } - $chars = mb_str_split( $string ); + $chars = Mbstring::mb_str_split( $string ); $string = ''; foreach ( $chars as $char ) { @@ -225,6 +229,17 @@ protected function split_chinese_string( $string, $table ) { return $string; } + /** + * Transliterate encoded url. + * + * @param string $url Url. + * + * @return string + */ + private function transliterate_encoded( $url ) { + return rawurlencode( $this->transliterate( urldecode( $url ) ) ); + } + /** * Get transliteration table. * diff --git a/classes/class-settings.php b/classes/class-settings.php index 2894252..077f4cc 100644 --- a/classes/class-settings.php +++ b/classes/class-settings.php @@ -790,7 +790,7 @@ protected function transpose_chinese_table( $table ) { $transposed_table = []; foreach ( $table as $key => $item ) { - $hieroglyphs = mb_str_split( $item ); + $hieroglyphs = Mbstring::mb_str_split( $item ); foreach ( $hieroglyphs as $hieroglyph ) { $transposed_table[ $hieroglyph ] = $key; }